Android 安卓推送通知出现,然后立即自动解除

Android 安卓推送通知出现,然后立即自动解除,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,我收到的推送通知会显示出来,然后立即自动取消。我想要删除它,所以用户必须手动关闭它或单击它转到应用程序。非常感谢您的帮助 private void sendNotification(Bundle msg, final int notID) { mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);

我收到的推送通知会显示出来,然后立即自动取消。我想要删除它,所以用户必须手动关闭它或单击它转到应用程序。非常感谢您的帮助

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 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);

你能发布你用来显示通知的代码吗?添加了sendNotification方法codeWelcome:)这是我的第一个答案;):P