【问题标题】:Exception: android.app.RemoteServiceException Bad notification posted from package异常:android.app.RemoteServiceException 从包发布的错误通知
【发布时间】:2018-06-18 07:42:39
【问题描述】:

我在 Play 商店有一个应用程序,最近我收到了很多关于 ActivityThread.java 的崩溃消息

致命异常

致命异常:android.app.RemoteServiceException 从包 XXX 发布的错误通知:无法扩展 RemoteViews:StatusBarNotification(pkg=XXX user=UserHandle{0} id=1 tag=null score=0: Notification(pri=0 contentView=XXX/0x1090065 vibrate=null sound= null defaults=0x0 flags=0x0 kind=[null]))

    alarmNotificationManager = (NotificationManager) this
            .getSystemService(Context.NOTIFICATION_SERVICE);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, MainActivity.class), 0);


    NotificationCompat.Builder alamNotificationBuilder = new NotificationCompat.Builder(
            this,"1").setContentTitle("Prayer Time Alert!").setSmallIcon(R.mipmap.icon_logo)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setDeleteIntent(createOnDismissedIntent(this,1))
            .setContentText(msg);


    alamNotificationBuilder.setContentIntent(contentIntent);
    alarmNotificationManager.notify(1, alamNotificationBuilder.build());

private PendingIntent createOnDismissedIntent(Context context, int notificationId) {
    Intent intent = new Intent(context, NotificationDismissedReceiver.class);
    intent.putExtra("com.my.app.notificationId", notificationId);

    PendingIntent pendingIntent =
            PendingIntent.getBroadcast(context.getApplicationContext(),
                    notificationId, intent, 0);
    return pendingIntent;

}
public class NotificationDismissedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
    int notificationId = intent.getExtras().getInt("com.my.app.notificationId");
  /* Your code to handle the event here */
    if (Global.mPlayer != null) {
        Global.mPlayer.stop();
    }
    NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    manager.cancel(notificationId);
}
}

【问题讨论】:

    标签: java android notifications


    【解决方案1】:

    把这个改成-:

    alarmNotificationManager.notify(1, alamNotificationBuilder.build());
    

    到:

    alarmNotificationManager.notify(0, alamNotificationBuilder.build());
    

    ID 应该与待处理意图和通知管理器中的情况相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-18
      • 1970-01-01
      • 2018-03-28
      • 2018-06-15
      • 2014-10-08
      相关资源
      最近更新 更多