[英]Broadcast service not getting called
Using following code 使用以下代码
Intent i = new Intent(this, BootUpReceiverRecall.class);
sendBroadcast(i);
<receiver android:process=":remote" android:name="BootUpReceiverRecall"></receiver>
public class BootUpReceiverRecall extends BroadcastReceiver
{
// Restart service every 30 seconds
private static final long REPEAT_TIME = 1000 * 30;
@Override
public void onReceive(Context context, Intent intent)
{
AlarmManager service = (AlarmManager) context
.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, BootUpReceiver.class);
PendingIntent pending = PendingIntent.getBroadcast(context, 0, i,
PendingIntent.FLAG_CANCEL_CURRENT);
Calendar cal = Calendar.getInstance();
// Start 30 seconds after boot completed
cal.add(Calendar.SECOND, 30);
//
// Fetch every 30 seconds
// InexactRepeating allows Android to optimize the energy consumption
service.setInexactRepeating(AlarmManager.RTC_WAKEUP,
cal.getTimeInMillis(), REPEAT_TIME, pending);
// service.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(),
// REPEAT_TIME, pending);
}
My BootUpReceiver never gets called. 我的BootUpReceiver永远不会被调用。 what wrong am i doing ?
我在做什么错?
You need to define it properly in AndroidManifest.xml : 您需要在AndroidManifest.xml中正确定义它:
<receiver
android:process=":remote"
android:name=".BootUpReceiverRecall" />
Take a look at "android:name" tag, 看一下“ android:name”标签,
you need to add a dot(".") before the "BootUpReceiverRecall" if it is in the same package as your application,but if it is not you can simple use the full name like "app.package.receivers.BootUpReceiverRecall". 如果与应用程序位于同一软件包中,则需要在“ BootUpReceiverRecall”之前添加点(“。”)。如果不是,则可以简单地使用全名,例如“ app.package.receivers.BootUpReceiverRecall”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.