Android-job: The JobRequest.Builder throw an exception is not very useful

Created on 6 Dec 2016  路  3Comments  路  Source: evernote/android-job

I have recived a crash report.

com.evernote.android.job.JobRequest$Builder.com.evernote.android.job.JobRequest$Builder setPersisted(boolean)(SourceFile:824)

Device

SM-G7200 Android 4.4.4 armeabi-v7a ROM:samsung/grandmaxltezc

I have to check it in advance

boolean hasBootPermission = JobUtil.hasBootPermission(BaseApplication.getAppContext());
JobRequest.Builder builder = new JobRequest.Builder(PushJob.TAG);
 if (hasBootPermission) {
    builder.setPersisted(true);
}

A little dirty.Is there a better solution?

help wanted

All 3 comments

You didn't attach the full stacktrace. I'm assuming the crash mentions, that the required boot completed permission is missing. We had similar issues with some devices and ended up doing the same:

new JobRequest.Build(PushJob.TAG)
    .setAAA()
    .setPersisted(JobUtil.hasBootPermission(context)
    .build()
    .schedule()

That works for us and I don't have a better solution. Also notice that the library reschedules all necessary jobs the next time it's being launched. So you don't have to do anything else and no job will get lost.

I know.But I don't know what happened to the samsung 4.4.4 device.
This is the stacktrace,very little.

#662 java.lang.IllegalStateException
Does not have RECEIVE_BOOT_COMPLETED permission, which is mandatory for this feature
com.evernote.android.job.JobRequest$Builder.com.evernote.android.job.JobRequest$Builder setPersisted(boolean)

com.evernote.android.job.JobRequest$Builder.com.evernote.android.job.JobRequest$Builder setPersisted(boolean)(SourceFile:824)
com.codoon.persistent.sync.SyncJob.void scheduleJob()(SourceFile:33)
com.codoon.snowx.ui.activity.SplashActivity$2.run(SourceFile:83)
android.os.Handler.handleCallback(Handler.java:733)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:136)
android.os.HandlerThread.run(HandlerThread.java:61)

I find the error message in :

public Builder setPersisted(boolean persisted) {
    if (persisted && !JobUtil.hasBootPermission(JobManager.instance().getContext())) {
        throw new IllegalStateException("Does not have RECEIVE_BOOT_COMPLETED permission, which is mandatory for this feature");
    }
    mPersisted = persisted;
    return this;
}

I think this is a special case and I will use setPersisted(JobUtil.hasBootPermission(context) .
Thank you!

I don't know what happened with those devices either. Maybe it's a custom ROM or Samsung did something really weird. Can the issue be closed?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vibin picture vibin  路  3Comments

froesmatheus picture froesmatheus  路  4Comments

krokyze picture krokyze  路  3Comments

tatocaster picture tatocaster  路  6Comments

ExploiTR picture ExploiTR  路  6Comments