【发布时间】:2026-01-04 19:40:01
【问题描述】:
点击“应用正在后台运行”的通知后,我需要打开我的应用,但是当我点击它时打开应用信息,我该如何避免这种情况并打开应用本身。
这是我用来显示此通知的代码:
Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
NotificationChannel channel = new NotificationChannel("Player", "Sync Service", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Service Name");
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.createNotificationChannel(channel);
Notification.Builder builder = new Notification.Builder(this, "Player")
.setContentTitle("Music Player")
.setContentText("My Music")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.setOngoing(true);
Notification notification = builder.build();
startForeground(1, notification);
观察。此应用确实使用后台服务,我不想隐藏此通知。
【问题讨论】:
标签: java android notifications background-service