Compatibility Information
Modifiy AndroidManifest.xml
Add Permission
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Add components
<service android:name="com.cobub.toaster.push.component.PushService"> <intent-filter> <action android:name="com.cobub.toaster.push.SYNC" /> </intent-filter> </service> <receiver android:name="com.cobub.toaster.push.component.CPushReceiver" android:permission="android.permission.RECEIVE_BOOT_COMPLETED" > <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> </intent-filter> </receiver>
Add the code
Call the following API as soon as possible after starting app:
CPushInterface.initPushService(Context ctx, String UID, String host, int port);
Initialize
CPushInterface.initPushService(Context ctx, String UID, String host, int port);
Set Channel
This method sets tag value for terminal device.
CPushInterface.setChannel(Context ctx, String channelName);
Read feedback
Report to PNS that notification has been clicked (read).
CPushInterface.sendReadFeedback(Context context, String mid, String expired);
Receive Push Content
The payload message is transferred via Broadcast. It’s needed to set a BroadcastReceiver to receive, and the Receiver needs to filter their app package name (package) of action, otherwise it can not receive the message, add the following to menifest:
<receiver android:name="com.cobub.toaster.push.TestReceiver" android:permission="com.cobub.toaster.push"> <intent-filter > <action android:name="com.cobub.toaster.push"/> </intent-filter> </receiver>
The data form PNS to mobile device contains the following content:
mid:“XXXXXX” data:“XXXXXX” expired:“XXXXXX” channel:“XXXXXXXX”
In Receiver the field can be retrieved by the following methods:
String msg = intent.getStringExtra("data"); String expired = intent.getStringExtra("expired"); String mid = intent.getStringExtra("mid");
Call according to the need Read feedback interface.