我已经创建了一个Android应用程序,该应用程序应该在启动后启动服务。 它在Nexus 5手机上工作得很好,但我无法使它在华为平板电脑(Mediapad X2)上工作。我正在使用Android 5.0/API 21.BOOT_COMPLETED没有收到
根据指南,清单具有适当的权限/意图。
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<receiver
android:name=".BootBroadcast"
android:enabled="true"
android:exported="true"
android:label="BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
我SO搜索类似问题(BOOT_COMPLETED not working Android),并添加了QUICKBOOT_POWERON意图,还有WAKE_LOCK权限,但一切都没有改变。
广播接收器刚刚开始服务
public class BootBroadcast extends BroadcastReceiver {
private static final String TAG = "GrandUnion-Boot";
@Override
public void onReceive(Context context, Intent intent) {
Log.e(TAG, "Boot_Completed RECEIVED");
try{
context.startService(new Intent(context,MyService.class));
Log.i(TAG, "Boot Completed - start service");
}catch(Exception e){
Log.e(TAG,e.toString());
}
}
}
可能重复与http://stackoverflow.com/questions/24882861/android-intent-action-boot-completed-intent-is-not-received-at-restart-or-reb – KostasC
我不认为它因为OP说他还加了Quickboot ..... – Opiatefuchs
你有没有尝试在'intent-filter'中加入' '? –
Knossos