【发布时间】:2020-11-19 22:55:07
【问题描述】:
我想通过通知自动启动全屏活动,但 setFullScreenIntent 有问题。我遵循了这个:https://developer.android.com/training/notify-user/time-sensitive 和互联网上的线程,但这对我来说不起作用。 我的通知出现了,但我必须按下它才能启动活动。
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationManager notificationManager = this.getSystemService(NotificationManager.class);
if (notificationManager != null && notificationManager.getNotificationChannel(NOTIFICATION_CHANNEL_ID) == null) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "channel_name", NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("channel_description");
notificationManager.createNotificationChannel(channel);
}
}
Intent fullScreenIntent = new Intent(this, ResultActivity.class);
fullScreenIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent fullScreenPendingIntent = PendingIntent.getActivity(this, 0,
fullScreenIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder =
new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Full Screen Notification")
.setContentText("Notification test text")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setFullScreenIntent(fullScreenPendingIntent, true);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(12345, notificationBuilder.build());
这是我的清单:
<uses-permission android:name="android.permission.USE_FULL_SCREEN_INTENT" />
<activity
android:name=".ResultActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" /> -->
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
谢谢!
【问题讨论】:
标签: android android-intent android-activity android-notifications