轉移自 LogDown 原文日期 May 30, 2014 10:14
之前介紹過用 Parse 來做 push,這次換成另一家服務廠商。 Lightspeed 官網: http://www.lightspeedmbs.com/。 它是由 arrownock 延伸而來的,專職於推播和即時訊息。 SDK 和官方說明文件必須註冊後才能取得。 目前筆者主攻 Android ,所以以下都針對 Android 開發部分介紹。 它的推播可以用 gcm 的方式也可以用 Lightspeed 自己的服務,筆者採用的是後者。
MyApplication.java public class MyApplication extends android.app.Application { @Override public void onCreate() { super.onCreate(); List channels = new ArrayList(); //must at least one channel channels.add("android"); try { /* * connection default use https, if devices not support, do this * AnPush.getInstance(getBaseContext()).setSecureConnection(false); */ AnPush.getInstance(getBaseContext()).register(channels); AnPush.getInstance(getBaseContext()).enable(); } catch (ArrownockException ex) { Log.e(TAG, ex.getMessage()); } } }
AndroidManifest.xml <application ...... android:name=".MyApplication" >
AndroidManifest.xml <meta-data android:name="com.arrownock.push.SERVICE_TYPE" android:value="ARROWNOCK" /> <meta-data android:name="com.arrownock.APP_KEY" android:value="arrownock_key"/> <meta-data android:name="com.arrownock.push.KEEPALIVE_INTERVAL_WIFI" android:value="14" /> <meta-data android:name="com.arrownock.push.KEEPALIVE_INTERVAL_2G" android:value="4" /> <meta-data android:name="com.arrownock.push.KEEPALIVE_INTERVAL_3G" android:value="4" /> <service android:name="com.arrownock.push.PushService" /> <receiver android:name="com.arrownock.push.PushBroadcastReceiver" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.USER_PRESENT" /> <action android:name="com.arrownock.push.PushService.MSG_ARRIVAL" /> <category android:name="android.intent.category.HOME" /> </intent-filter> <meta-data android:name="com.arrownock.push.BroadcastReceiver.ArrivalActivity" android:value="MainActivity" /> </receiver>
AndroidManifest.xml <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.READ_PHONE_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WAKE_LOCK" />