Android-極光推送集成流程

一、添加依賴

//極光推送
compile 'cn.jiguang.sdk:jpush:3.0.0'
compile 'cn.jiguang.sdk:jcore:1.0.0'

二、配置參數(shù)

//defaultConfig{
    JPUSH_PKGNAME : applicationId,
    JPUSH_APPKEY : "501e0f31b4e163e1", //JPush上注冊(cè)的包名對(duì)應(yīng)的appkey.
    JPUSH_CHANNEL : "developer-default", //暫時(shí)填寫(xiě)默認(rèn)值即可.   
}

三、配置清單文件

1.添加必要的權(quán)限
2.注冊(cè)廣播接受者
    <!-- User defined. 用戶自定義的廣播接收器 -->
    <receiver
        android:name=".bookstore.receiver.PushReceiver"
        android:enabled="true">
        <intent-filter>

            <!-- Required 用戶注冊(cè)SDK的intent -->
            <action android:name="cn.jpush.android.intent.REGISTRATION"/>
            <!-- Required 用戶接收SDK消息的intent -->
            <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED"/>
            <!-- Required 用戶接收SDK通知欄信息的intent -->
            <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED"/>
            <!-- Required 用戶打開(kāi)自定義通知欄的intent -->
            <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED"/>
            <!-- 接收網(wǎng)絡(luò)變化 連接/斷開(kāi) since 1.6.3 -->
            <action android:name="cn.jpush.android.intent.CONNECTION"/>

            <category android:name="com.laikan.reader"/>
        </intent-filter>
    </receiver>

四、創(chuàng)建Receiver類(lèi)

    public class PushReceiver extends BroadcastReceiver{
    private static final String TAG = "PushReceiver";

    private NotificationManager nm;
    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d("lyt","receiver called");
        if (null == nm) {
            nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        }

        Bundle bundle = intent.getExtras();
    //     Log.d(TAG, "onReceive - " + intent.getAction() + ", extras: " + AndroidUtil.printBundle(bundle));

        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            Log.d(TAG, "JPush用戶注冊(cè)成功");

        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "接受到推送下來(lái)的自定義消息");

        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            Log.d(TAG, "接受到推送下來(lái)的通知");

            receivingNotification(context,bundle);

        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            Log.d(TAG, "用戶點(diǎn)擊打開(kāi)了通知");

    //      openNotification(context,bundle);
            openLaikan(context);

        } else {
            Log.d(TAG, "Unhandled intent - " + intent.getAction());
        }
    }

五、在Application中初始化Jpush

JPushInterface.init(this);
JPushInterface.setDebugMode(true);  // 極光推送 設(shè)置開(kāi)啟日志,發(fā)布時(shí)請(qǐng)關(guān)閉日志
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容