java.lang.IllegalStateException: Not allowed to start service Intent { act=android.intent.action.BOOT_COMPLETED flg=0x9000010 cmp=com.xxx.xxx/.service.MyIntentService (has extras) }: app is in background uid UidRecord{6ca99a3 u0a7 RCVR idle change:uncached procs:1 seq(0,0,0)}
这个错误是由于你的应用在后台时试图启动服务引起的。在 Android 中,自 Android 8.0(API 级别 26)起,后台限制(Background Execution Limits)被引入,这意味着在后台运行的应用有一些限制,比如不能随意启动服务。
方法1:前台服务
异常:app is in background uid UidRecord/stadid not then call Service.startForeground
方法2:获取system权限
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.xxx"
android:sharedUserId="android.uid.system">
在manifest中加入android:sharedUserId=“android.uid.system”,然后重新做Android包。具体是不是一定要做Android包才能生效,我不清楚,只是提供一种解决思路