仅在 android 11 和 10 中出现错误,其他都很好,已经检查过这个其他问题,我的代码似乎没问题,有什么想法吗?
startForeground 失败并出现 Bad notification for startForeground
android.app.RemoteServiceException:startForeground 的错误通知
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String message = intent.getStringExtra("message");
int id = intent.getIntExtra("ID", 1);
Uri ringtoneUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
Intent firstActivityIntent = new Intent(this, FirstActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addParentStack(FirstActivity.class);
stackBuilder.addNextIntent(firstActivityIntent);
Intent notificationUpdateIntent = new Intent(this, UpdateNotificationActivity.class);
notificationUpdateIntent.putExtra("ID", id);
stackBuilder.addNextIntent(notificationUpdateIntent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(id, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_1_ID)
.setContentTitle("Reminder")
.setContentText(message)
.setSmallIcon(R.drawable.noteappicon)
.setStyle(new NotificationCompat.BigTextStyle())
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.build();
startForeground(1, notification);
Run Code Online (Sandbox Code Playgroud)
我在 …