我的广播接收器没有收到
My broadcast receiver is not receiving
我使用带有警报管理器的广播接收器每 60 秒访问一次 Web 服务,当我在不同 class 中使用我的广播接收器时它似乎工作正常但当我声明一个接收器时它没有调用我的 activity
我的代码在下面
public static void startAlarm(Context context) {
Intent locationAlarm = new Intent(context, GetLocation.class);
AlarmManager alarms = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Calendar updateTime = Calendar.getInstance();
PendingIntent recurringAlarm = PendingIntent.getBroadcast(context, 0,
locationAlarm, PendingIntent.FLAG_CANCEL_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP,
updateTime.getTimeInMillis() + 500, UPDATE_INTERVAL,
recurringAlarm);
}
广播接收者:
public class GetLocation extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.d("Started Service");
}
}
我的清单文件:
<receiver android:name="com.sample.sample.listeners$GetLocation" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
请指正我的错误。我的启动服务方法从未调用过
您的清单文件中有错字。您已将 $GetLocation 替换为 .GetLocation
<receiver android:name="com.sample.sample.listeners.GetLocation" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
我使用带有警报管理器的广播接收器每 60 秒访问一次 Web 服务,当我在不同 class 中使用我的广播接收器时它似乎工作正常但当我声明一个接收器时它没有调用我的 activity
我的代码在下面
public static void startAlarm(Context context) {
Intent locationAlarm = new Intent(context, GetLocation.class);
AlarmManager alarms = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Calendar updateTime = Calendar.getInstance();
PendingIntent recurringAlarm = PendingIntent.getBroadcast(context, 0,
locationAlarm, PendingIntent.FLAG_CANCEL_CURRENT);
alarms.setRepeating(AlarmManager.RTC_WAKEUP,
updateTime.getTimeInMillis() + 500, UPDATE_INTERVAL,
recurringAlarm);
}
广播接收者:
public class GetLocation extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
LogUtil.d("Started Service");
}
}
我的清单文件:
<receiver android:name="com.sample.sample.listeners$GetLocation" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
请指正我的错误。我的启动服务方法从未调用过
您的清单文件中有错字。您已将 $GetLocation 替换为 .GetLocation
<receiver android:name="com.sample.sample.listeners.GetLocation" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>