用户工具

站点工具


差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

后一修订版
前一修订版
toaster:android-developer-guide [2015/03/18 15:17]
cobub 创建
toaster:android-developer-guide [2017/07/14 11:18] (当前版本)
行 1: 行 1:
-xx+~~Title:​Cobub Toaster android开发者指南 - 开源移动应用运营平台 - 移动统计、移动推送解决方案 - Cobub 移动开发者中心~~ 
 +{{description>​Cobub Toaster android开发者指南}} 
 +{{keywords>​Cobub Toaster,​开源移动应用分析,​移动分析,​移动应用分析,​android,​开发者指南}} 
 +====== Android开发者指南 ====== 
 + 
 + 
 +版本支持 
 + 
 +  * 兼容Android2.2以上(API 8以上) 
 +  * SDK版本v1.0 
 +===== 集成步骤 ===== 
 + 
 + 
 +修改**AndroidManifest.xml** 
 + 
 +添加权限 
 +<​code>​ 
 +<​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"/></​code>​ 
 +添加组件 
 +<​code>​ 
 +<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>​ 
 +</​code>​ 
 +**添加代码** 
 + 
 +在APP启动以后尽早调用:​ 
 +<​code>​ 
 +CPushInterface.initPushService(Context ctx, String UID, String host, int port);</​code>​ 
 +===== API参考说明 ===== 
 + 
 + 
 +**初始化** 
 +<​code>​ 
 +CPushInterface.initPushService(Context ctx, String UID, String host, int port);</​code>​ 
 +ctx:上下文参数 
 +UID:必须传入UID 
 +host:推送服务器绑定的域名或IP地址 
 +port:推送服务器绑定的端口 
 + 
 +**设置Channel** 
 + 
 +此方法为终端设备设定TAG值 
 +<​code>​ 
 +CPushInterface.setChannel(Context ctx, String channelName);</​code>​ 
 +ctx:上下文参数 
 +channelName:channel的值,这里即为为终端设置TAG,例如“location:​Beijing” 
 + 
 +**已阅反馈** 
 + 
 +向推送服务器PNS报告通知栏消息已被点击。 
 +<​code>​ 
 +CPushInterface.sendReadFeedback(Context context, String mid, String expired);</​code>​ 
 +ctx:上下文参数 
 +mid:推送消息中的mid 
 +expired:推送消息中的expired时间 
 + 
 +**接收推送** 
 + 
 +透传消息采用Broadcast传递,需要自定义一个BroadcastReceiver来接收,Receiver需要过滤自身app包名(package)的action,否则无法收到消息,如下内容需加入menifest: 
 +<​code>​ 
 +<​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></​code>​ 
 +从推送服务器推送到手机的消息包含如下内容: 
 +<​code>​ 
 +    mid:“XXXXXX” 
 +    data:“XXXXXX” 
 +    expired:“XXXXXX” 
 +    channel:“XXXXXXXX” </​code>​ 
 +在Receiver中可以通过以下方式取出字段: 
 +<​code>​ 
 +String msg = intent.getStringExtra("​data"​);​ 
 +String expired = intent.getStringExtra("​expired"​);​ 
 +String mid = intent.getStringExtra("​mid"​);</​code>​ 
 +可根据需要调用已阅反馈接口。
toaster/android-developer-guide.1426663062.txt.gz · 最后更改: 2017/07/14 11:13 (外部编辑)