BroadcastReceiver没被调用?

时间:2014-04-19 11:23:59

标签: android broadcastreceiver alarmmanager

我在启动活动中使用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>

任何人都可以提供帮助吗?

1 个答案:

答案 0 :(得分:0)

您正在创建变量gpsintent但警报管理器获取的pendingIntent未在示例代码中分配