2017-10-03 4 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() 
.. 
} 

편집 :

넥서스 7 안드로이드 5.1 작동하고 제대로

넥서스 5 안드로이드 6.0. 1이 작동 중입니다. ectly too

Xioami Redmi 참고 2 MIUI 7.3.2.0이 설치된 Android 5.0.2는 작동하지 않으며 응용 프로그램을 종료하면 알림이 사라집니다.

+0

어떤 기기를 사용하고 있으며 최근 목록에서 앱을 삭제 하시겠습니까? –

+0

알림을 트리거하는 것은 무엇입니까? 서비스? –

+0

Xiaomi Redmi Note2, 다른 앱의 알림이 올바르게 작동합니다. 예, 최근 목록에서 앱을 삭제합니다. onCreate() 메소드의 주된 (그리고 유일한) 활동 내에서 알림을 트리거하고 있습니다. 서비스를 통해 시도했습니다. 결과는 두 경우 모두 동일합니다. 응용 프로그램을 닫을 때까지 알림이 표시됩니다 (목록에서 제거). – LuckyLue

답변

0

사용이 :

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

는 도움이되기를 바랍니다!

+0

최근 목록에서 응용 프로그램을 제거한 후에 알림이 사라집니다. – LuckyLue

관련 문제