2017-10-03 18 views
-1

アプリを終了した後、アンドロイド通知が消える:/なぜですか?私は、この通知を作成するアプリケーションを閉じた後ではなく、それをクリックした後に消える永続的な通知を作成したいと思います。誰かが助けることができますか?アプリの終了後にアンドロイド通知が消える

MainActivityクラス:

private void createNotification() { 

    Intent intent = new Intent(this, eTutorActivity.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 

    Bitmap icon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher); 

    Notification noti = new NotificationCompat.Builder(this) 
      .setContentTitle("xxx") 
      .setContentText("xxx") 
      .setTicker("xxx") 
      .setSmallIcon(android.R.drawable.ic_dialog_info) 
      .setLargeIcon(icon) 
      .setOngoing(true) 
      .setAutoCancel(true) 
      .setContentIntent(pIntent) 
      .build(); 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 

    notificationManager.notify(0, noti); 
} 

MainActivityクラスのonCreateアクション:

protected void onCreate(Bundle savedInstanceState) { 
.. 
createNotification() 
.. 
} 

EDIT:

ネクサス7のAndroid 5.1は、Android 6.0を正しく

ネクサス5取り組んでいます。 1は働いているまったく同じ

Xioami Redmi注2 MIUI 7.3.2.0のAndroid 5.0.2は動作していないため、アプリケーションを終了すると通知が消えます。

+0

あなたはどのデバイスを使用していますか、最近のリストからアプリを削除しますか? –

+0

通知をトリガしているのは何ですか?サービス? –

+0

Xiaomi Redmi注2、他のアプリからの通知が正しく機能します。 はい、最近のリストからアプリを削除しています。 私はサービス経由で試していましたが、今はonCreate()メソッドの主な(そして唯一の)アクティビティの中で通知をトリガーしています。どちらの場合も結果は同じです。通知は、アプリケーションを閉じる(リストから削除する)まで表示されます。 – LuckyLue

答えて

0

はこれを使用します。

noti.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT; 
notificationManager.notify(0, noti); 

はそれが役に立てば幸い!

+0

最新のリストからアプリケーションを削除した後、通知が消えます。 – LuckyLue

関連する問題