Android 如何停止自动打开应用程序的推送通知?

Android 如何停止自动打开应用程序的推送通知?,android,push-notification,Android,Push Notification,我有一个带有推送通知的Android应用程序。我的一些设备出现问题,当我发送推送通知时,用户的应用程序会自动打开。我不想那样做。我希望通知正常显示,如果用户点击它,应用程序就会打开 如何防止应用程序自动打开 以下是我的推送通知意图中的代码: Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.setFlags( Intent.FLAG_ACTIVITY_CLEA

我有一个带有推送通知的Android应用程序。我的一些设备出现问题,当我发送推送通知时,用户的应用程序会自动打开。我不想那样做。我希望通知正常显示,如果用户点击它,应用程序就会打开

如何防止应用程序自动打开

以下是我的推送通知意图中的代码:

Intent notificationIntent = new Intent(this, MainActivity.class);

notificationIntent.setFlags(
        Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent contentIntent = PendingIntent.getActivity(this, requestID, notificationIntent,
        PendingIntent.FLAG_UPDATE_CURRENT);

// Display a notification with an icon, message as content, and default sound. It also
// opens the app when the notification is clicked.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
        .setContentTitle(title)
        .setContentText(message)
        .setColor(0xFF221E80)
        .setDefaults(Notification.DEFAULT_SOUND)
        .setAutoCancel(true)
        .setFullScreenIntent(contentIntent, true)
        .setContentIntent(contentIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(
        Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, builder.build());

如果您查看
NotificationCompat.Builder
的文档,您会发现问题出在
setFullScreenIntent

在那次电话会议上:

启动而不是将通知发布到状态栏的意图。仅用于要求用户立即注意的极高优先级通知,例如用户明确设置为特定时间的来电或闹钟。如果此设备用于其他用途,请给用户一个选项来关闭它并使用普通通知,因为这可能会造成极大的破坏

在某些平台上,当用户使用设备时,系统UI可能会选择显示提示通知,而不是启动此意图


您应该从生成器中删除
setFullScreenIntent

谢谢!我真不知道怎么会不被注意到!正在按预期工作!=)没问题,很高兴一切正常,很高兴编码!