Android 推送通知出现后立即自动关闭

Android push notification comes up then instantly gets dismissed automatically

我收到推送通知,显示后立即自动关闭。我想要它,所以用户必须手动关闭它或单击它以转到应用程序。非常感谢任何帮助。

private void sendNotification(Bundle msg, final int notID) {

        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        Intent myintent = new Intent(this, Main.class);
        myintent.putExtras(msg);
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                myintent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setTicker(myintent.getStringExtra("ticker"));
        mBuilder.setContentText(myintent.getStringExtra("contentText"));
        mBuilder.setContentTitle(myintent.getStringExtra("contentTitle"));
        mBuilder.setWhen(System.currentTimeMillis());
        mBuilder.setAutoCancel(false);

    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

尝试使用此代码。 PendingIntent 和 setAutoCancel 的差别很小。

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, HomeScreen.class), 0);
    builder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_notification_icon)
            .setContentTitle(getString(R.string.app_name))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setSound(customSoundURI).setAutoCancel(true)
            .setContentText(msg);

    builder.setContentIntent(contentIntent);