Android java.lang.IllegalArgumentException: No such service ComponentInfo JobScheduler

十年热恋 提交于 2019-12-04 10:03:21

问题


I tried to create a simple JobScheduler job just to see how it works. but I keep getting this exception on runtime, I can't figure it out as I followed the guides step by step.

This is my call:

        ComponentName componentName = new ComponentName(getApplicationContext(), TestService.class);
    JobInfo jobInfo = new JobInfo.Builder(1, componentName).setPeriodic(300000)
            .setRequiredNetworkType(JobInfo.NETWORK_TYPE_ANY).build();

    JobScheduler tm =
            (JobScheduler) getApplicationContext().getSystemService(Context.JOB_SCHEDULER_SERVICE);
    tm.schedule(jobInfo);

TestService doesn't do anything other than extends JobService.


回答1:


You need to add the permission android.permission.BIND_JOB_SERVICE into your AndroidManifest.xml

...
<service android:name=".TestService"
     android:permission="android.permission.BIND_JOB_SERVICE"
     android:exported="true"/>
...
</application>




回答2:


Try clean project. It was my case.




回答3:


My issue was that my Service was defined as an static inner class. The issue resolved itself once I moved the service class into it's own Java file



来源:https://stackoverflow.com/questions/33364096/android-java-lang-illegalargumentexception-no-such-service-componentinfo-jobsch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!