轉移自 LogDown 原文日期 May 29, 2014 13:34,現今 Parse 官方 server 已關閉,僅提供 SDK 自架 Server
Parse 官網: https://parse.com/ 它提供的不只有推播訊息,還有其他功能,例如雲端資料建置,這會在下次介紹。 SDK 和官方說明文件必須註冊後才能取得。 目前筆者主攻 Android ,所以以下都針對 Android 開發部分介紹。
MyApplication.java public class MyApplication extends android.app.Application { @Override public void onCreate() { super.onCreate(); Parse.initialize(this, applicationId, clientKey); PushService.setDefaultPushCallback(this. MainActivity.class); ParseInstallation.getCurrentInstallation().saveInBackground(); } }
AndroidManifest.xml <application ...... android:name=".MyApplication" >
AndroidManifest.xml <service android:name="com.parse.PushService" /> <receiver android:name="com.parse.ParseBroadcastReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> </intent-filter> </receiver> <receiver android:name="com.parse.GcmBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND"> <intent-filter> <action android:name="com.google.android.c2dm.intent.RECEIVE" /> <action android:name="com.google.android.c2dm.intent.REGISTRATION" /> <!-- IMPORTANT: Change "com.parse.starter" to match your app's package name. --> <category android:name="com.parse.starter" /> </intent-filter> </receiver>
AndroidManifest.xml <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /> <!-- IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below to match your app's package name + ".permission.C2D_MESSAGE". --> <permission android:protectionLevel="signature" android:name="com.parse.starter.permission.C2D_MESSAGE" /> <uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />