Android极光推送通过不同的通知内容跳入不同的页面
16lz
2022-07-23
1、在注册清单中加入
2、编写receiver
package com.youzheng.slqx.activity;import android.content.BroadcastReceiver;import android.content.Context;import android.content.Intent;import android.os.Bundle;import android.text.TextUtils;import android.util.Log;import org.json.JSONException;import org.json.JSONObject;import java.util.Iterator;import java.util.logging.Logger;import cn.jpush.android.api.JPushInterface;/** * 自定义接收器 * * 如果不定义这个 Receiver,则: * 1) 默认用户会打开主界面 * 2) 接收不到自定义消息 */public class MyTReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { try { Bundle bundle = intent.getExtras(); if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) { String regId = bundle.getString(JPushInterface.EXTRA_REGISTRATION_ID); //send the Registration Id to your server... } else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) { } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) { int notifactionId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID); } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) { //用户点击通知会走的方法 //获取推送消息的方法 String content = bundle.getString(JPushInterface.EXTRA_ALERT); // 在这里可以自己写代码去定义用户点击后的行为 if(context != null){ Log.e("content",content); //例如 如果推送内容以【消息】开头 则点击后跳转到消息的Activity 否则跳转到主页面 if(content.startsWith("【气象预警】")||content.startsWith("【水利预警】")){//判断内容的条件 Intent i = new Intent(context, YJJCActivity.class); //打开消息界面 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } if(content.startsWith("【国突预警】")){ Intent i = new Intent(context, YJTXActivity.class); //打开主界面 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); } Intent i = new Intent(context, YJJKActivity.class); //打开主界面 i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(i); }else{ } } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK.equals(intent.getAction())) { //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码,比如打开新的Activity, 打开一个网页等.. } else if(JPushInterface.ACTION_CONNECTION_CHANGE.equals(intent.getAction())) { boolean connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false); } else { } } catch (Exception e){ } }
3、极光有一个bug就是必须展开通知点击才能进入指定的页面。????
4、还有一个注意的地方,极光推送的内容,不包含标题的,切记切记,可尝试打印内容,通过内容的特定文字进行判断。
更多相关文章
- 浅析Android中的消息机制-解决:Only the original thread that cr
- Android异步消息机制之Handler
- android 复制、剪切、粘贴
- [RK3399][Android7.1.1] WifiAp:开机默认打开wifi热点
- Android内容提供者源码
- Android(安卓)SDK Manager无法更新的解决
- Android开发之消息处理机制(一)——Handler
- Android(安卓)TabHost使用、动态加载内容
- 解决Android(安卓)Studio和Android(安卓)SDK Manager无法在线更