estou com um problema para iniciar um service no android logo quando o celular liga segui vários tutoriais porém sempre ocasiona esse erro
06-04 23:56:27.305 10948-10948/pluswallpapers.devmarques.com.wallpapersall E/AndroidRuntime: FATAL EXCEPTION: main Process: pluswallpapers.devmarques.com.wallpapersall, PID: 10948 java.lang.RuntimeException: Unable to start receiver pluswallpapers.devmarques.com.wallpapersall.YouWillNeverDestroy.StartServiceBoot: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=pluswallpapers.devmarques.com.wallpapersall/.YouWillNeverDestroy.MyService }: app is in background uid UidRecord{2368819 u0a298 RCVR idle change:uncached procs:1 seq(0,0,0)} at android.app.ActivityThread.handleReceiver(ActivityThread.java:3216) at android.app.ActivityThread.-wrap17(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6520) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) Caused by: java.lang.IllegalStateException: Not allowed to start service Intent { flg=0x10000000 cmp=pluswallpapers.devmarques.com.wallpapersall/.YouWillNeverDestroy.MyService }: app is in background uid UidRecord{2368819 u0a298 RCVR idle change:uncached procs:1 seq(0,0,0)} at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1521) at android.app.ContextImpl.startService(ContextImpl.java:1477) at android.content.ContextWrapper.startService(ContextWrapper.java:650) at android.content.ContextWrapper.startService(ContextWrapper.java:650) at pluswallpapers.devmarques.com.wallpapersall.YouWillNeverDestroy.StartServiceBoot.onReceive(StartServiceBoot.java:15) at android.app.ActivityThread.handleReceiver(ActivityThread.java:3209) at android.app.ActivityThread.-wrap17(Unknown Source:0) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1688) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6520) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
A classe start boot é essa, tem tudo declarado certinho lá no manifest, o service, o startboot completed, acredito que possa ser algo para inicializar o serviço nesse classe do broadcast mas não sei como resolver...
public class StartServiceBoot extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())){
Intent serviceIntent = new Intent(context, MyService.class);
context.startService(serviceIntent);
}
}
}
lembrando que não é uma activity apenas um serviço em background, se o serviço é startado por uma activity funciona normalmente, acredito que eu deva estar infringindo algo da segurança do android para não inicializar no broadcast.