0

다음과 같은 스키마가 있습니다 BOOT_COMPLETE 의도 ->BroadcastReciever 시작한 다음 NotificationIntentService으로 보내기 WakefullBroadcastReceiver -> 시작합니다. 내가 BOOT_COMPLETE 의도에 스키마를 변경하는 경우WakefulBroadcastReceiver가 실행되지 않습니다

하지만 내 WakefullBroadcastReceiver은 결코 작동하지 않습니다 ->BroadcastReciever ->NotificationIntentService에 의도를 전송.

public class BootBroadcastReciever extends BroadcastReceiver { 
     @Override 
     public void onReceive(Context context, Intent intent) { 
      if (!App.isRunning) { 
       Log.d("wakefull", "start"); 
       Intent startIntent = new Intent("SOMEACTION"); 
       //startIntent.setAction(Utils.NOTIFY_INTENT); 
       PendingIntent startPIntent = PendingIntent.getService(context, 0, startIntent, 0); 
       AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); 
       am.setRepeating(AlarmManager.RTC_WAKEUP, 
         SystemClock.elapsedRealtime() + 3000, 5000, startPIntent); 
       App.isRunning = true; 
      } 
      Log.e("bool",App.isRunning+""); 
     } 
    } 

WakefulBroadcastReceiver :

public class SimpleWakefulReciever extends WakefulBroadcastReceiver { 

    @Override 
    public void onReceive(Context context, Intent intent) { 
     Log.e("wakefull","received"); 
     Intent service = new Intent(context, NotificationWakefulIntentService.class); 
     startWakefulService(context,service); 
    } 
} 

NotificationIntentService :

public class NotificationWakefulIntentService extends IntentService { 

    public NotificationWakefulIntentService() { 
     super("NotificationWakefulIntentService"); 
    } 

    @Override 
    protected void onHandleIntent(Intent intent) { 
     Log.d("time",(System.currentTimeMillis()/1000)+""); 
     SimpleWakefulReciever.completeWakefulIntent(intent); 
    } 
} 

매니페스트 :

<receiver android:name=".broadCastReciever.BootBroadcastReciever" android:enabled="true" android:exported="false"> 
      <intent-filter> 
       <action android:name="android.intent.action.BOOT_COMPLETED"/> 
       <action android:name="START"/> 
      </intent-filter> 
     </receiver> 

     <receiver android:name=".wakefullBroadcastReciever.SimpleWakefulReciever"> 
      <intent-filter> 
       <action android:name="SOMEACTION"/> 
       <action android:name="WAKEFUL"/> 
      </intent-filter> 
     </receiver> 

     <service 
      android:name=".wakefulService.NotificationWakefulIntentService" 
      android:enabled="true"> 
      <intent-filter> 
       <action android:name="NOTIFY_INTENT" /> 
      </intent-filter> 
     </service> 
012 everething 완벽

브로드 캐스트 리시버를 작동

답변

0

먼저 <intent-filter> 요소를 제거하고 <action android:name="android.intent.action.BOOT_COMPLETED"/> 요소를 제거하십시오. 임의의 타사 앱이 필요할 때마다 해당 구성 요소를 시작하지 않으려면 구성 요소에 <intent-filter>을 두지 마십시오.

다음

대체 :

Intent startIntent = new Intent("SOMEACTION"); 
PendingIntent startPIntent = PendingIntent.getService(context, 0, startIntent, 0); 

로 :

Intent startIntent = new Intent(context, SimpleWakefulReciever.class); 
PendingIntent startPIntent = PendingIntent.getBroadcast(context, 0, startIntent, 0); 

이 더 이상 액션 문자열을 사용하지 귀하의 Intent를 해결하고 당신이를 트리거하기 위해 노력하고있다 이후 PendingIntentgetBroadcast()를 사용하도록 수정 BroadcastReceiver.

그런 다음 Android 5.1 이상의 경우보다 자주 반복 알람을 사용할 수 없으므로 5000을 값 60000으로 바꿉니다.

+0

정말 고마워요! 이제 작동합니다. Android 버전 15를 사용하여 기기를 테스트하고 있습니다. 알람을 위해 1 분을 기다리지 않습니다. – Turbozanik

관련 문제