所以我有一个BroadcastReceiver
看起来像这样的:
public class UpdateReceiver extends BroadcastReceiver {
public UpdateReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 10);
System.out.println("Broadcast received");
PendingIntent operation = PendingIntent.getService(context, 0,new Intent("REFRESH_THAT"), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, System.currentTimeMillis(), cal.getTimeInMillis(), operation);
}
}
这就是我所说的BroadcastReceiver
Intent in = new Intent ("REFRESH_BROADCAST");
sendBroadcast(in);
这是我在 AndroidManifest
文件中的意图过滤器
<service android:name = ".services.RefreshService">
<intent-filter>
<action android:name="REFRESH_THAT"/>
</intent-filter>
</service>
<receiver android:name=".services.UpdateReceiver">
<intent-filter>
<action android:name="REFRESH_BROADCAST"/>
</intent-filter>
</receiver>
BroadcastReceiver
收到了没有任何问题的广播,但AlarmManager
似乎什么也没做。如果我称operation.send()
它可以正常工作,那么我认为AlarmManager
.