好的,所以我尝试了我能找到的一切,它不起作用。这是我的代码。有人可以告诉我为什么它不会调用接收器吗?
AndroidManifest.xml
...
<receiver android:name=".AlarmReciever" />
...
AlarmReciever.java
public class AlarmReciever extends BroadcastReceiver
{
private static final Logger LOGGER = Logger.getLogger(LogService.class);
@Override
public void onReceive(Context context, Intent intent)
{
LOGGER.debug("BroadcastReceiver, in onReceive:");
}
}
设备监视器.java
public class DeviceMonitor extends Service
{
public int onStartCommand(Intent intent, int flags, int startld)
{
LOGGER.debug("alarmmanger settting from on start");
AlarmManager alarmMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent I = new Intent(this, AlarmReciever.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, I, 0);
Calendar time = Calendar.getInstance();
time.setTimeInMillis(System.currentTimeMillis());
time.add(Calendar.SECOND, 5);
alarmMgr.set(AlarmManager.RTC_WAKEUP, time.getTimeInMillis(), pendingIntent);
LOGGER.debug("alarmmanger set from on start");
}
}