91嫩草国内在线,韩国理论电影免费看,6969精品视频在线观看,1024在线视频精品免费,色中色污,饭冈佳奈子在线

用戶工具

站點工具


Android開發者指南

版本支持

  • 兼容Android2.2以上(API 8以上)
  • SDK版本v1.0

集成步驟

修改AndroidManifest.xml

添加權限

<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"/>

添加組件

<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>

添加代碼

在APP啟動以后盡早調用:

CPushInterface.initPushService(Context ctx, String UID, String host, int port);

API參考說明

初始化

CPushInterface.initPushService(Context ctx, String UID, String host, int port);

ctx:上下文參數 UID:必須傳入UID host:推送服務器綁定的域名或IP地址 port:推送服務器綁定的端口

設置Channel

此方法為終端設備設定TAG值

CPushInterface.setChannel(Context ctx, String channelName);

ctx:上下文參數 channelName:channel的值,這里即為為終端設置TAG,例如“location:Beijing”

已閱反饋

向推送服務器PNS報告通知欄消息已被點擊。

CPushInterface.sendReadFeedback(Context context, String mid, String expired);

ctx:上下文參數 mid:推送消息中的mid expired:推送消息中的expired時間

接收推送

透傳消息采用Broadcast傳遞,需要自定義一個BroadcastReceiver來接收,Receiver需要過濾自身app包名(package)的action,否則無法收到消息,如下內容需加入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>

從推送服務器推送到手機的消息包含如下內容:

    mid:“XXXXXX”
    data:“XXXXXX”
    expired:“XXXXXX”
    channel:“XXXXXXXX” 

在Receiver中可以通過以下方式取出字段:

String msg = intent.getStringExtra("data");
String expired = intent.getStringExtra("expired");
String mid = intent.getStringExtra("mid");

可根據需要調用已閱反饋接口。

toaster/android-developer-guide.txt · 最后更改: 2017/07/14 11:18 (外部編輯)