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、还有一个注意的地方,极光推送的内容,不包含标题的,切记切记,可尝试打印内容,通过内容的特定文字进行判断。

更多相关文章

  1. 浅析Android中的消息机制-解决:Only the original thread that cr
  2. Android异步消息机制之Handler
  3. android 复制、剪切、粘贴
  4. [RK3399][Android7.1.1] WifiAp:开机默认打开wifi热点
  5. Android内容提供者源码
  6. Android(安卓)SDK Manager无法更新的解决
  7. Android开发之消息处理机制(一)——Handler
  8. Android(安卓)TabHost使用、动态加载内容
  9. 解决Android(安卓)Studio和Android(安卓)SDK Manager无法在线更

随机推荐

  1. Android相对布局管理器RelativeLayout
  2. Android: 如何在Fragment中使用上下文Con
  3. EditText设置IME动作问题
  4. Android AIDL创建Service
  5. 国外著名 Android(安卓)开发者的信息
  6. Android常用adb命令总结(二)
  7. Android NDK R9环境配置,开发教程
  8. Android调用摄像头识别图片的形状和颜色
  9. Android(安卓)解决getColor()或getDrawab
  10. Android(安卓)Looper(cpp)用法举例