Android 集成云信推送 (一)通知栏跳转

第一步: 注册自定义推送消息处理

NIMPushClient.registerMixPushMessageHandler(DemoMixPushMessageHandler())

第二步

public class DemoMixPushMessageHandler implements MixPushMessageHandler {

   
    @Override
    public boolean onNotificationClicked(Context context, Map<String, String> payload) {
       
        boolean existMainActivity = isProcessExist(context,android.os.Process.myPid());
        Intent notifyIntent;

        if (existMainActivity) {
            if (context instanceof MixPushActivity) {
               
                notifyIntent =  new Intent(context, MainActivity.class);
            }else {
               
                notifyIntent = new Intent();
                notifyIntent.setComponent(initLaunchComponent(context));
                notifyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                notifyIntent.setAction(Intent.ACTION_VIEW);
                notifyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // 必须
            }
        }else {
            notifyIntent =  new Intent(context, SplashActivity.class);
        }
        context.startActivity(notifyIntent);
        return true;
    }

    private ComponentName initLaunchComponent(Context context) {
        ComponentName launchComponent;
        StatusBarNotificationConfig config = DemoCache.getNotificationConfig();
        Class<? extends Activity> entrance = config.notificationEntrance;
        if (entrance == null) {
            launchComponent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()).getComponent();
        } else {
            launchComponent = new ComponentName(context, entrance);
        }
        return launchComponent;
    }


    // 将音视频通知 Notification 缓存,清除所有通知后再次弹出 Notification,避免清除之后找不到打开正在进行音视频通话界面的入口
    @Override
    public boolean cleanMixPushNotifications(int pushType) {
        Context context = DemoCache.getContext();
        NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        if (manager != null) {
            manager.cancelAll();
        }
        return true;
    }

    /**
     *  判断进程是否存活
     */
    public static boolean isProcessExist(Context context, int pid) {
        ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningAppProcessInfo> lists ;
        if (am != null) {
            lists = am.getRunningAppProcesses();
            for (ActivityManager.RunningAppProcessInfo appProcess : lists) {
                if (appProcess.pid == pid) {
                    LogUtils.e("==================isProcessExist========333333");
                    return true;
                }
            }
        }
        return false;
    }


}

第三步:

自定义该应用初始的 StatusBarNotificationConfig
 StatusBarNotificationConfig config = new StatusBarNotificationConfig();
        // 点击通知需要跳转到的界面
  config.notificationEntrance = MixPushActivity.class;

MixPushActivity 里面

public class MixPushActivity extends Activity {
    private static final String TAG = "MixPushActivity";

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
        parseIntent();
    }

    void parseIntent() {

        Intent intent = getIntent();
        if (intent == null) {
            return;
        }
        ArrayList<IMMessage> msgListExtra  = (ArrayList<IMMessage>) intent.getSerializableExtra(NimIntent.EXTRA_NOTIFY_CONTENT);

        new DemoMixPushMessageHandler().onNotificationClicked(MixPushActivity.this,null);
    }

    @Override
    protected void onStop() {
        super.onStop();
        finish();
    }


}




oppo 通知栏点击事件
华为通知栏点击事件请看
Android 集成云信推送 (三)踩过的那些坑

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值