【发布时间】:2016-01-18 13:26:28
【问题描述】:
我创建了一个应在 BOOT 后启动服务的 Android 应用程序。 它在 Nexus 5 手机上运行良好,但我无法在华为平板电脑(Mediapad X2)上运行。我正在使用 Android 5.0 / API 21。
根据指南,清单具有适当的权限/意图。
<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());
}
}
}
【问题讨论】:
-
我不认为这是重复的,因为 OP 说他还添加了 Quickboot.....
-
您是否尝试将
<category android:name="android.intent.category.DEFAULT" />添加到intent-filter? -
嗨@KostasC,正如我在帖子中提到的,我搜索了 SO 并考虑了他们的回复(例如添加 QUICKBOOT_POWERON 操作)但没有结果。华为设备是否还有其他“隐藏”意图?
-
...有些设备在清单中的声明有一些奇怪的行为。例如你的接收器:android:name=".BootBroadcast"。有时,如果您改为写:“com.yourpackage.BootBroadcast”,我的意思是全名,它只会有所帮助。之后,清理项目,从设备上卸载并重新安装。
标签: android