我試圖用這種方式處理:在BroadcastReceiver
開始AlarmManager
重複動作,它會發送意向到IntentService
,服務寫入日誌。現在,我從日誌中看到,BroadcastReceiver
收到意向,啓動AlarmManager
,但IntentService
從不發生。這裏有什麼可能是錯的?無法修復與AlarmManager通知的IntentService
清單:
<receiver android:name=".wakefullBroadcastReciever.SimpleWakefulReciever" android:enabled="true" android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="START"/>
</intent-filter>
</receiver>
<service
android:name=".wakefulService.NotificationWakefulIntentService"
android:enabled="true">
<intent-filter>
<action android:name="NOTIFY_INTENT" />
</intent-filter>
</service>
WakefulReciever:
public class SimpleWakefulReciever extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (!App.isRunning) {
Log.d("wakefull", "start");
Intent startIntent = new Intent(context, NotificationWakefulIntentService.class);
startIntent.setAction(Utils.NOTIFY_INTENT);
PendingIntent startPIntent = PendingIntent.getBroadcast(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;
}
}
}
IntentService:
public class NotificationWakefulIntentService extends IntentService {
public NotificationWakefulIntentService() {
super("NotificationWakefulIntentService");
}
@Override
protected void onHandleIntent(Intent intent) {
Log.d("time",(System.currentTimeMillis()/1000)+"");
}
}