强制下线极光推送

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34900897/article/details/79975863

为了遗忘特意在这里记录一下也顺便回忆:

现在manifest里面注册

<!-- 极光推送 User defined. 用户自定义的广播接收器 -->
<receiver
    android:name=".receiver.MyReceiver"
    android:enabled="true">
    <intent-filter>

        <!-- Required 用户注册SDK的intent -->
        <action android:name="cn.jpush.android.intent.REGISTRATION" />
        <action android:name="cn.jpush.android.intent.UNREGISTRATION" />
        <!-- 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 用户打开自定义通知栏的intent -->
        <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
        <!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
        <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />
        <!-- 接收网络变化 连接/断开 since 1.6.3 -->
        <action android:name="cn.jpush.android.intent.CONNECTION" />

        <category android:name="包名" />
    </intent-filter>
</receiver>

注册极光manifest

然后自定义类继承广播:

@Override
public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();
    Log.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));

    if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
        String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID);
        Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId);
        //send the Registration Id to your server...

    } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_TITLE));
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MESSAGE));
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_CONTENT_TYPE));
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_APP_KEY));
        Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle.getString(JPushInterface.EXTRA_MSG_ID));
        processCustomMessage(context, bundle);//强制下线收到推送会走这一步

    } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[MyReceiver] 接收到推送下来的通知");
        int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
        Log.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);

        String pushMessage = bundle.getString(JPushInterface.EXTRA_ALERT);
    } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
        String msg = bundle.getString(JPushInterface.EXTRA_ALERT);
        // TODO: 2018/3/6 点击状态栏回调

    } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
        Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
        //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..

    } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
        boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
        Log.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
    } else {
        Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
    }
}processCustomMessage(context, bundle);//强制下线收到推送会走这一步

    } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "[MyReceiver] 接收到推送下来的通知");
        int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);
        Log.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: " + notifactionId);

        String pushMessage = bundle.getString(JPushInterface.EXTRA_ALERT);
    } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
        String msg = bundle.getString(JPushInterface.EXTRA_ALERT);
        // TODO: 2018/3/6 点击状态栏回调

    } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) {
        Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle.getString(JPushInterface.EXTRA_EXTRA));
        //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等..

    } else if (JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) {
        boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false);
        Log.w(TAG, "[MyReceiver]" + intent.getAction() + " connected state change to " + connected);
    } else {
        Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.getAction());
    }
}

注重红色部分,根据后台定义的规则而定

阅读更多

没有更多推荐了,返回首页