Contenu connexe Similaire à 마이크로소프트 Azure 에서 안드로이드 Push 구현과 Data 처리 (20) 마이크로소프트 Azure 에서 안드로이드 Push 구현과 Data 처리11. 우리의 MS 문서는 친절합니다.
검색은 구글이죠.
http://azure.microsoft.com/en-us/documentation/articles/
mobile-services-android-get-started-push/
Push notification using Azure Mobile service
12. 역시 구글은 친절합니다.
Get started Notification Hubs
http://azure.microsoft.com/en-us/documentation/articles/
notification-hubs-android-get-started/
42. MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
… ( 생략 )
NotificationsManager.handleNotifications(this, SENDER_ID, MyHandler.class);
!
gcm = GoogleCloudMessaging.getInstance(this);
!
String connectionString = “CONNECTION_STRING";
hub = new NotificationHub(“NOTIFICATION_HUB_NAME”, connectionString, this);
!
registerWithNotificationHubs();
51. MyHandler.java
!
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
NotificationCompat.Builder builder;
Context ctx;
!
@Override
public void onReceive(Context context, Bundle bundle) {
ctx = context;
String nhMessage = bundle.getString("msg");
System.out.println("RECEIVE");
!
sendNotification(nhMessage);
Toast.makeText(context, nhMessage, 3).show();
}
class MyHandler 안에
52. MyHandler.java
!
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
!
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
new Intent(ctx, MainActivity.class), 0);
!
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(ctx)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("Notification Hub Demo")
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setContentText(msg);
!
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
class MyHandler 안에
60. script
function azurex_push() {
var azure = require('azure');
var notificationHubService = azure.createNotificationHubService(‘NOTIFICATION_HUB_NAME’,
‘CONNECTION_STRING');
notificationHubService.gcm.send(null,'{"data":{"msg" : "Hello from Mobile Services!"}}',
function (error)
{
if (!error) {
console.warn("Notification successful");
}
else
{
console.warn("Notification failed" + error);
}
}
);
}
69. DB에 넣는 기능을 만듭니다.
Item item = new Item();
item.Text = "Awesome item";
mClient.getTable(Item.class).insert(item, new
TableOperationCallback<Item>() {
public void onCompleted(Item entity, Exception exception,
ServiceFilterResponse response) {
if (exception == null) {
// Insert succeeded
} else {
// Insert failed
}
}
});
71. 이 문서에 사용한 소스 코드는
http://xenonix.com 에서 내려 받으실 수 있습니다.