Android O系统(android8.0)手机极光推送失败

这个问题。。。

是有点坑。。。。

项目中极光推送集成的比较早,所以就没在意,今天有用户反应收不到推送,哈哈,赶紧去官网看看,果然

首先替换了所有的jar文件进行升级

其次,推送收到后需要自己弹框显示,而且Android O版本中还添加了

NotificationChannel channel = new NotificationChannel("渠道id", "渠道名称",“渠道优先级”);
 @Override
    public void onReceive(Context context, Intent intent) {
        try {
            Bundle bundle = intent.getExtras();
            Log.e(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                Log.e(TAG, "8.0处理了");
                NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
                int notificationId = bundle.getInt(JPushInterface.EXTRA_NOTIFICATION_ID);//定义通知id
                String channelId = context.getPackageName();//通知渠道id
                String channelName = "消息通知";//"PUSH_NOTIFY_NAME";//通知渠道名
                int importance = NotificationManager.IMPORTANCE_HIGH;//通知级别
                NotificationChannel channel = new NotificationChannel(channelId , channelName, channelId);
//                channel.enableLights(true);//设置闪光灯
                channel.setLightColor(Color.RED);
                channel.enableVibration(true);//设置通知出现震动
                channel.setShowBadge(true);
                channel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
                notificationManager.createNotificationChannel(channel);

                NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
                Intent notificationIntent = new Intent(context, NameSeachActivity.class);
                notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                String message = bundle.getString(JPushInterface.EXTRA_ALERT);
                String title = bundle.getString(JPushInterface.EXTRA_NOTIFICATION_TITLE);
                String s = bundle.getString(JPushInterface.EXTRA_EXTRA);
                Intent intent0= new Intent(context, MainActivity.class);
                PendingIntent pi = PendingIntent.getActivity(context, 0, intent0, PendingIntent.FLAG_UPDATE_CURRENT);
                builder.setContentTitle(title)//设置通知栏标题
                        .setContentText(message)
                        .setWhen(System.currentTimeMillis())//通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
                        .setSmallIcon(R.mipmap.new_app_icon)//设置通知小ICON
                        .setChannelId(channelId)
                        .setDefaults(Notification.DEFAULT_ALL)
                        .setContentIntent(pi);
                Notification notification = builder.build();
                notification.flags |= Notification.FLAG_AUTO_CANCEL;
                if (notificationManager != null) {
                    notificationManager.notify(notificationId , notification);
                }
            } else if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
                    //跳转
            }
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, "极光推送出错:" + e.getMessage());
        }

Android O系统会根据你的渠道类别,显示不同的通知需求,用户可以选择关闭某渠道的通知,并设置优先级

如上图所示:

该应用有3个渠道

附上判断8.0是否开启权限通知的方法:

NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Boolean notificationManager.areNotificationsEnabled();

到此就全部解决了。。。

大家有什么高见,可以留言哦。

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值