没有这样的服务 ComponentInfo Android JobScheduler
No such service ComponentInfo Android JobScheduler
我正在尝试使用 JobScheduler 安排作业,但出现异常,好像我没有在 AndroidManifest.xml 中添加服务:
java.lang.IllegalArgumentException: No such service ComponentInfo{br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos/br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos.JobSchedulerService}
at android.os.Parcel.readException(Parcel.java:1687)
at android.os.Parcel.readException(Parcel.java:1636)
at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:158)
at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:42)
at br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos.JobSchedulerService.scheduleJob(JobSchedulerService.java:55)
at br.com.modeladoryoga.pontocorpofidelidade.ihm.activity.SplashActivity.run(SplashActivity.java:31)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6111)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
构建:
JobScheduler mJobScheduler = (JobScheduler) context
.getSystemService(JOB_SCHEDULER_SERVICE);
JobInfo.Builder mJobBuilder =
new JobInfo.Builder(idServicoNotificacao,
new ComponentName(JobSchedulerService.class.getPackage().getName(),
JobSchedulerService.class.getName()));
mJobBuilder.setMinimumLatency(3000);
if (mJobScheduler != null && mJobScheduler.schedule(mJobBuilder.build())
<= JobScheduler.RESULT_FAILURE) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
AndroidManifest.xml:
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
...
<service android:name=".ihm.servicos.JobSchedulerService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
<receiver android:name=".ihm.servicos.NotificationServiceStarterReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
我已经尝试 运行 几次,清理和构建都没有成功。有遇到同样问题的人可以帮助我吗?
之后
mJobBuilder.setMinimumLatency(3000);
插入
int ret = mJobScheduler.schedule(mJobBuilder.build());
if (ret<= JobScheduler.RESULT_FAILURE) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
使用new ComponentName(Context pkg, String cls)
JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder mJobBuilder = new JobInfo.Builder(idServicoNotificacao,new ComponentName(context,JobSchedulerService.class));
mJobBuilder.setMinimumLatency(3000);
if (mJobScheduler != null && mJobScheduler.schedule(mJobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
您可以使用 getPackageName()
作为 ComponentName()
的第一个参数:
JobInfo.Builder mJobBuilder =
new JobInfo.Builder(idServicoNotificacao,
new ComponentName(getPackageName(),
JobSchedulerService.class.getName()));
我正在尝试使用 JobScheduler 安排作业,但出现异常,好像我没有在 AndroidManifest.xml 中添加服务:
java.lang.IllegalArgumentException: No such service ComponentInfo{br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos/br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos.JobSchedulerService}
at android.os.Parcel.readException(Parcel.java:1687)
at android.os.Parcel.readException(Parcel.java:1636)
at android.app.job.IJobScheduler$Stub$Proxy.schedule(IJobScheduler.java:158)
at android.app.JobSchedulerImpl.schedule(JobSchedulerImpl.java:42)
at br.com.modeladoryoga.pontocorpofidelidade.ihm.servicos.JobSchedulerService.scheduleJob(JobSchedulerService.java:55)
at br.com.modeladoryoga.pontocorpofidelidade.ihm.activity.SplashActivity.run(SplashActivity.java:31)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6111)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
构建:
JobScheduler mJobScheduler = (JobScheduler) context
.getSystemService(JOB_SCHEDULER_SERVICE);
JobInfo.Builder mJobBuilder =
new JobInfo.Builder(idServicoNotificacao,
new ComponentName(JobSchedulerService.class.getPackage().getName(),
JobSchedulerService.class.getName()));
mJobBuilder.setMinimumLatency(3000);
if (mJobScheduler != null && mJobScheduler.schedule(mJobBuilder.build())
<= JobScheduler.RESULT_FAILURE) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
AndroidManifest.xml:
...
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
...
<service android:name=".ihm.servicos.JobSchedulerService"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true"/>
<receiver android:name=".ihm.servicos.NotificationServiceStarterReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
我已经尝试 运行 几次,清理和构建都没有成功。有遇到同样问题的人可以帮助我吗?
之后
mJobBuilder.setMinimumLatency(3000);
插入
int ret = mJobScheduler.schedule(mJobBuilder.build());
if (ret<= JobScheduler.RESULT_FAILURE) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
使用new ComponentName(Context pkg, String cls)
JobScheduler mJobScheduler = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
JobInfo.Builder mJobBuilder = new JobInfo.Builder(idServicoNotificacao,new ComponentName(context,JobSchedulerService.class));
mJobBuilder.setMinimumLatency(3000);
if (mJobScheduler != null && mJobScheduler.schedule(mJobBuilder.build()) != JobScheduler.RESULT_SUCCESS) {
Log.d(TAG_SERVICO, "Unable to schedule the service!");
}
您可以使用 getPackageName()
作为 ComponentName()
的第一个参数:
JobInfo.Builder mJobBuilder =
new JobInfo.Builder(idServicoNotificacao,
new ComponentName(getPackageName(),
JobSchedulerService.class.getName()));