【发布时间】:2014-04-19 21:17:17
【问题描述】:
我在启动活动中使用 Alarmmanager 重复执行 BroadcastReceiver 中的某些内容,但 BroadcastReceiver 没有被触发。我的代码如下:
MainActivity.class:
AlarmManager manager = (AlarmManager) getBaseContext().getSystemService(Context.ALARM_SERVICE);
Intent gpsintent =new Intent(getBaseContext(),gps_sendback_alarm_receiver.class);
PendingIntent.getService(getBaseContext(), 0, gpsintent, PendingIntent.FLAG_UPDATE_CURRENT);
Calendar now = Calendar.getInstance();
manager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, now.getTimeInMillis(), int_gps_sendback_period, pendingIntent);
gps_sendback_alarm_receiver.class:
public void onReceive(Context context, Intent intent) {
//send back the GPS location
}
清单:
<application>
<receiver android:name="com.example.xmobiler.gps_sendback_alarm_receiver" android:enabled="true"/>
</application>
有人可以帮忙吗?
【问题讨论】:
标签: android broadcastreceiver alarmmanager