2012年11月22日 星期四

Parse.com 超簡單 架Mobile Android Server教學 5.Push Notifications

Android Push Notifications

This tutorial provides you with a step-by-step guide to configuring your Android application for push.
Push notifications let your application notify a user of new messages or events even when the user is not actively using your application. On Android devices, when a device receives a push notification, your application's icon and a message appear in the status bar. When the user taps the notification, they are sent to your application. Notifications can be broadcast to all users, such as for a marketing campaign, or sent to just a subset of users, to give personalized information.
The Parse library provides push notifications by running a background service that keeps an internet connection to the Parse Cloud. This method of push notification is compatible back to Android 1.5 and does not require an active Google account on the phone.

1. Registering for the Push Service

AndroidManifest.xml 加下述 service 和 receiver
 tag:
android:name="com.parse.PushService" />
android:name="com.parse.ParseBroadcastReceiver">
  
     android:name="android.intent.action.BOOT_COMPLETED" />
     android:name="android.intent.action.USER_PRESENT" />
  

2. Setting Permissions

加 權限
android:name="android.permission.INTERNET" />
android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
android:name="android.permission.VIBRATE" />
android:name="android.permission.ACCESS_NETWORK_STATE" />

3. Enable Push Notifications

試一試吧
PushService.subscribe(this, "", YourActivity.class);
"" //這個是註冊 Parse channel,上例是 全部,你可以定義自已的。