마이크로소프트 Azure 에서 안드로이드 Push 구현과 Data 처리

2,351 views
2,083 views

Published on

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
  • 유용한 자료 잘보겠습니다.^^
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
2,351
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
21
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide

마이크로소프트 Azure 에서 안드로이드 Push 구현과 Data 처리

  1. 1. Windows Azure! Push & DB 용영환 마이크로소프트 멜팅팟 세미나 2014년 4월 24일
  2. 2. • 용영환! • http://xenonix.com! • xenonix@gmail.com
  3. 3. Notification services ! = Push
  4. 4. 두 가지가 있습니다. ! Mobile service Push Notification hub
  5. 5. Mobile service Push
  6. 6. Notification Hub http://msdn.microsoft.com/en-us/library/jj927170.aspx
  7. 7. http://www.slideshare.net/youngjaekim58/20140403-tech-daysazurenotificationhubservicebus
  8. 8. http://www.slideshare.net/youngjaekim58/20140403-tech-daysazurenotificationhubservicebus
  9. 9. 특징 http://www.slideshare.net/youngjaekim58/20140403-tech-daysazurenotificationhubservicebus Mobile service push ! ! 가볍게 Push를 사용하고 싶을 때 ! Notification Hub! 대량의 단체 Push를 전송하고 싶을 때
  10. 10. 우리의 MS 문서는 친절합니다. 검색은 구글이죠. http://azure.microsoft.com/en-us/documentation/articles/ mobile-services-android-get-started-push/ Push notification using Azure Mobile service
  11. 11. 역시 구글은 친절합니다. Get started Notification Hubs http://azure.microsoft.com/en-us/documentation/articles/ notification-hubs-android-get-started/
  12. 12. 그런데… 알려드린 Azure 문서에 살짝 생략된 내용들이 있습니다. ! 그러므로 이 발표 자료를 따라하시기를 권장합니다.
  13. 13. account.windowsazure.com
  14. 14. https://console.developers.google.com
  15. 15. azuresdk-android-1.1.5.zip
  16. 16. 먼저 안드로이드 프로젝트를 생성합니다.
  17. 17. google-play-service가 안보이면
  18. 18. google-play-service가 안보이면
  19. 19. AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.GET_ACCOUNTS"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <permission android:name="com.xenonix.azurex.permission.C2D_MESSAGE" android:protectionLevel="signature" /> <uses-permission android:name="com.xenonix.azurex.permission.C2D_MESSAGE"/>
  20. 20. MainActivity.java public class MainActivity extends Activity { ! private String SENDER_ID = “SENDER_ID"; private GoogleCloudMessaging gcm; private NotificationHub hub;
  21. 21. MainActivity.java @SuppressWarnings("unchecked") private void registerWithNotificationHubs() { new AsyncTask() { @Override protected Object doInBackground(Object... params) { try { String regid = gcm.register(SENDER_ID); hub.register(regid); } catch (Exception e) { return e; } return null; } }.execute(null, null, null); }
  22. 22. 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();
  23. 23. CONNECTION STRING Service Bus 메뉴
  24. 24. SENDER_ID
  25. 25. import android.os.AsyncTask; import com.google.android.gms.gcm.*; import com.microsoft.windowsazure.messaging.*; import com.microsoft.windowsazure.notifications.NotificationsManager; MainActivity.java 안에 SDK 파일을 libs 안에 복사 그리고 F5 키 클릭!
  26. 26. MyHandler.class 가 없기 때문!!! ! 만들어 주자!
  27. 27. 여기서 MyHandler는 Receiver 입니다.
  28. 28. AndroidManifest.xml <receiver android:name="com.microsoft.windowsazure.notifications.NotificationsBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <!-- Receives the actual messages. --> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <!-- Receives the registration id. --> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <category android:name="com.xenonix.azurex" /> </intent-filter> </receiver> <application> </application> 안에
  29. 29. 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 안에
  30. 30. 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 안에
  31. 31. 이제 Push를 날려봅니다.
  32. 32. 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); } } ); }
  33. 33. DB를 사용해 보겠습니다.
  34. 34. AndroidManifest.xml 에 <uses-permission android:name="android.permission.INTERNET" /> MainActivity.java 에 import com.microsoft.windowsazure.mobileservices.*; private MobileServiceClient mClient; onCreate( ) 에
  35. 35. MainActivity.java 에 import com.microsoft.windowsazure.mobileservices.*; private MobileServiceClient mClient; onCreate( ) 에 mClient = new MobileServiceClient( "https://azurex.azure-mobile.net/", “RnBqhfpTezpdVDRhYM…생략”, this );
  36. 36. Item 클래스를 만듭니다. package com.xenonix.azurex; ! public class Item { ! public String Id; public String Text; }
  37. 37. 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 } } });
  38. 38. 이 문서에 사용한 소스 코드는
 http://xenonix.com 에서 내려 받으실 수 있습니다.

×