1

android Lollipop에 알림을 표시하는 문제가 있습니다. 응용 프로그램이 열리면 알림이 잘 표시되지만 응용 프로그램이 닫히면 표시되지 않습니다. 안드로이드의 4x 버전에서 모든 것이 제대로 작동합니다. 여기에 방법 내가이 문제라고 생각 그들에게android Lollipop. 알림이 작동하지 않습니다.

@TargetApi(Build.VERSION_CODES.LOLLIPOP) 
    private void sendNotification(String body, String title, String badge) { 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.putExtra("from_notify", true); 
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this, Integer.valueOf(badge), intent, 
       PendingIntent.FLAG_ONE_SHOT); 

     Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
       .setSmallIcon(R.drawable.ic_stat_name) 
       .setContentTitle(title) 
       .setContentText(body) 
       .setPriority(Notification.PRIORITY_HIGH) 
       .setShowWhen(true) 
       .setVisibility(Notification.VISIBILITY_PUBLIC) 
       .setAutoCancel(true) 
       .setSound(defaultSoundUri) 
       .setContentIntent(pendingIntent); 

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

     notificationManager.notify(0, notificationBuilder.build()); 
    } 
+0

내 롤리팝 장치에서 코드를 확인한 결과 완벽하게 작동합니다. 활동과 방송 수신기에서 시작하는 두 경우 모두에서 테스트되었습니다. 활동이 종료되었는지 확인하기 위해 수신자는 BOOT 조치에 응답합니다. 문제는 다른 곳에서 발생합니다. 테스트 장치의 제조업체는 무엇입니까? 일부 제조업체는 일부 "앱 최적화"를 추가로 수행합니다. 예를 들어 Huawei의 경우 문자 그대로 강제로 앱을 중지하므로 방송 수신기가 작동하지 않으며 설명 된 동작과 일치합니다. '강제 정지'는 실행기에서 다시 시작될 때까지 앱을 사용 중지합니다. – mhenryk

답변

0

를 표시하는 것입니다 :

앱이 닫힐 때, 모든 응용 프로그램의 데이터를, 알림 및 정적 데이터를 포함 지워집니다 당신이 만들고 싶어 이렇게 알림은 서비스에서 보내야 할 때마다 항상 작동합니다 (서비스 클래스 생성 및 백그라운드에서 실행). 당신은 단지 서비스 클래스에서 다른 클래스에서 알림을 보낼 수

public class YourService extends Service { 
@Override 
public int onStartCommand(Intent intent, int flags, int startId) { 
    //send your notifications here 
    return START_STICKY; 
} 
@Override 
public IBinder onBind(Intent intent) { 
    return null; 
} 
} 

참고하지만 이후 앱 정적 데이터를 유지하는 데 도움이 있기 때문에 당신은 백그라운드에서 서비스를 실행해야합니다 :

이 시도 폐쇄 됐어.이 일은 나를 위해 일했다.

이 정보가 도움이되기를 바랍니다.

+0

사실이 아닙니다. 진행중인 알림 만 서비스 백업을 요구합니다. 질문에있는 것과 같은 일반 알림은 어디서나 시작할 수 있습니다. – mhenryk

+0

방금 ​​나는 (나는) 생각, 나는 로리팝으로 일하지 않았다. 나는 당신이 대답을 빨리 찾길 바래, 행운을 빈다. – phoenix

관련 문제