重新启动后的Android广播接收器未运行
我使用了这个权限:重新启动后的Android广播接收器未运行,android,service,alarmmanager,android-reboot,Android,Service,Alarmmanager,Android Reboot,我使用了这个权限: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> 重新启动后,棒棒糖中仍然没有调用它,但在棉花糖中它正在运行。尝试将这一行放在接收器的意图过滤器中 <action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" /> 每当平台引导完成时,都会广
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
重新启动后,棒棒糖中仍然没有调用它,但在棉花糖中它正在运行。尝试将这一行放在接收器的意图过滤器中
<action android:name="android.intent.action.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE" />
每当平台引导完成时,都会广播带有android.intent.action.boot\u completed action的intent。您需要注册您的应用程序才能收到此意向。要注册,请将其添加到AndroidManifest.xml
<receiver android:name=".ServiceManager">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
由于我们正在启动该服务,因此必须在AndroidManifest中提及:
<service android:name=".LocationService">
<intent-filter>
<action android:name="com.bootservice.test.DataService"/>
</intent-filter>
</service>
<receiver android:name=".ServiceManager">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
public class ServiceManager extends BroadcastReceiver {
Context mContext;
private final String BOOT_ACTION = "android.intent.action.BOOT_COMPLETED";
@Override
public void onReceive(Context context, Intent intent) {
// All registered broadcasts are received by this
mContext = context;
String action = intent.getAction();
if (action.equalsIgnoreCase(BOOT_ACTION)) {
//check for boot complete event & start your service
startService();
}
}
private void startService() {
//here, you will start your service
Intent mServiceIntent = new Intent();
mServiceIntent.setAction("com.bootservice.test.DataService");
mContext.startService(mServiceIntent);
}
}
<service android:name=".LocationService">
<intent-filter>
<action android:name="com.bootservice.test.DataService"/>
</intent-filter>
</service>