Android关于极光推送收到空白通知的问题

产生此问题的原因:

由于项目里面使用ShortcuBadger第三方库来实现桌面角标,这个桌面角标会发一条空的通知,所以才会出现推送的时候出现空白通知。

 

 

 

 

如果 项目中不得不使用这两个结合,就再项目中添加一个BadgeIntentService这个服务,这个是demo中有的,在这个里面删除收到的空白通知,这样就可以解决问题了。

BadgeIntentService

 

package com.clps.plane.service;

import android.app.IntentService;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;

import com.clps.plane.tools.picker.utils.LogUtils;

public class BadgeIntentService extends IntentService {

    private int notificationId = 0;

    public BadgeIntentService() {
        super("BadgeIntentService");
    }

    private NotificationManager mNotificationManager;

    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart(intent, startId);
        mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        LogUtils.i("onHandleIntent########");
        if (intent != null) {
            LogUtils.i(intent.hasExtra("badgeCount")+"########" + intent.getAction());
            int badgeCount = intent.getIntExtra("badgeCount", -1);
            mNotificationManager.cancel(notificationId);
            notificationId++;
//            Notification.Builder builder = new Notification.Builder(getApplicationContext())
//                .setContentTitle("")
//                .setContentText("")
//                .setSmallIcon(R.mipmap.ic_logo);
//            Notification notification = builder.build();
            ShortcutBadger.applyNotification(getApplicationContext(), notification, badgeCount);
//            mNotificationManager.notify(notificationId, notification);
        }
    }
}

 

 

 

添加角标

1.在onRecive里面启动服务

 

public void onReceive(Context context, Intent intent) {
    try {
        Bundle bundle = intent.getExtras();
        Logger.d(TAG, "[MyReceiver] onReceive - " + intent.getAction() + ", extras: " + printBundle(bundle));
        context.startService(new Intent(context, BadgeIntentService.class));//启动服务

 

 

2.在收到通知的时候添加桌面角标

 

else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
    //显示桌面角标,每收到一条通知就加一个
    try {
        msgNum = msgNum + 1;
        ShortcutBadger.applyCount(context, msgNum);
    } catch (Exception e) {
        e.printStackTrace();
    }

 

 

 

 

删除角标

我这里删除角标是在MainActivity的onResume方法里面实现的

 

try {
    MyReceiver.msgNum = 0;//吧消息条数初始化为0
    ShortcutBadger.removeCount(instance); //每次打开app,就清除所有的角标,
} catch (Exception e) {
    e.printStackTrace();
}
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        instance.startService(new Intent(instance, BadgeIntentService.class).putExtra("badgeCount", 0));
    }
}, 500);

 

 

 

 

 

 

 

 

能够快速的解决此问题,还得感谢,极光推送平台的技术支持。

我这里把帮我解决这个问题的技术邮箱分享出来,有问题可以给这个邮箱发邮件,邮箱:support<support@jpush.cn>

 

 

 

觉得有用的,就给妹子一个赞吧,么么哒害羞

 

 

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值