当前位置: 首页 > 知识库问答 >
问题:

异常:Android.app.RemoteServiceException从包发布的错误通知

龙德海
2023-03-14

致命异常:Android.app.RemoteServiceException从包xxx发布的错误通知:无法展开以下内容的RemoteViews:StatusBarNotification(PKG=xxx User=UserHandle{0}ID=1 Tag=null Score=0:notification(PRI=0 ContentView=xxx/0x1090065震动=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);
}
}

共有1个答案

苏宜人
2023-03-14

将此更改为-:

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

致-:

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

id应与挂起意图和通知管理器中的id相同。

 类似资料: