百度云推送(一)

学习要点:

1.应用配置

2.账号绑定接口

3.标签设置接口(option)

4.标签群发接口

5.全局群发接口

6.通知返回数据


1.应用配置

AndroidManifest.xml

<!-- Push service 运行需要的权限 -->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WRITE_SETTINGS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_DOWNLOAD_MANAGER"/>
    <uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
    <uses-permission android:name="android.permission.DISABLE_KEYGUARD" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />



<!-- 自定义Application -->
<application
        android:name="com.csz.push.DemoApplication"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" />


/**
*    如果之前没写 必须给空实现 如果之前写了 必须让FrontiaApplication
*    做为基类
*/
public class DemoApplication extends FrontiaApplication{
        @Override
    public void onCreate() {
        super.onCreate();
        //TODO my thing
    }
}


<!-- 主Activity可选配置属性 -->
    android:launchMode="singleTask"


<!-- push必须的receviver和service声明 -->
        <receiver android:name="com.baidu.android.pushservice.PushServiceReceiver"
            android:process=":bdservice_v1">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                <action android:name="com.baidu.android.pushservice.action.notification.SHOW" />
                <action android:name="com.baidu.android.pushservice.action.media.CLICK" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.baidu.android.pushservice.RegistrationReceiver"
            android:process=":bdservice_v1">
            <intent-filter>
                <action android:name="com.baidu.android.pushservice.action.METHOD" />
                <action android:name="com.baidu.android.pushservice.action.BIND_SYNC" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PACKAGE_REMOVED"/>
                <data android:scheme="package" />
            </intent-filter>                  
        </receiver>
        <service
            android:name="com.baidu.android.pushservice.PushService"
            android:exported="true"
            android:process=":bdservice_v1" />
        <!-- push结束 -->


<!-- push应用自定义消息receiver声明 -->
        <receiver android:name="com.csz.push.PushMessageReceiver">
            <intent-filter>
                <!-- 接收push消息 -->
                <action android:name="com.baidu.android.pushservice.action.MESSAGE" />
                <!-- 接收bind,unbind,fetch,delete等反馈消息 -->
                <action android:name="com.baidu.android.pushservice.action.RECEIVE" />
                <action android:name="com.baidu.android.pushservice.action.notification.CLICK" />
            </intent-filter>
        </receiver>


<!-- 在百度开发者中心注册API Key -->
        <meta-data android:name="api_key" android:value="Riqkd1iLijA1tqatkd5*****" />


你可能感兴趣的:(百度云推送)