1

i'm using a firebase job dispatcher api to run a service in background. In Marshmallow it is working fine, but while coming to Oreo devices it not working. it is showing error or warning messages like

2019-02-04 14:20:22.285 2525-5699/? E/NetworkScheduler: Dropping task as app's play services SDK version does not support Android O. Either update the SDK or lower your app's target SDK version. Package: com.webappclouds.jobserviceexample

I already done what is mentioned in firebase job dispatcher api step in git hub.

MainActiviy.java

package com.webappclouds.jobserviceexample;    
import android.app.job.JobInfo;    
import android.app.job.JobScheduler;    
import android.content.ComponentName;    
import android.support.v7.app.AppCompatActivity;    
import android.os.Bundle;    
import android.util.Log;    
import android.view.View;    
import android.widget.Button;    
import com.firebase.jobdispatcher.Constraint;    
import com.firebase.jobdispatcher.FirebaseJobDispatcher;    
import com.firebase.jobdispatcher.GooglePlayDriver;    
import com.firebase.jobdispatcher.Job;    
import com.firebase.jobdispatcher.Lifetime;    
import com.firebase.jobdispatcher.RetryStrategy;    
import com.firebase.jobdispatcher.Trigger;       
public class MainActivity extends AppCompatActivity {

String TAG="MAIN ACTIVITY";
FirebaseJobDispatcher dispatcher;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    dispatcher = new FirebaseJobDispatcher(new GooglePlayDriver(this));

}

public void startjob(View view) {
    Log.d(TAG, "startjob: ");
    Job job = createJob(dispatcher);
    dispatcher.mustSchedule(job);

}

public void stopjob(View view) {
    Log.d(TAG, "cancelJob: ");
    dispatcher.cancelAll();
}

public Job createJob(FirebaseJobDispatcher dispatcher) {
    Log.d(TAG, "createJob: ");
    Job job = dispatcher.newJobBuilder()
            // persist the task across boots
            .setLifetime(Lifetime.FOREVER)
            // Call this service when the criteria are met.
            .setService(MakeService.class)
            // unique id of the task
            .setTag("LocationJob")
            .setReplaceCurrent(true)
            // We are mentioning that the job is not periodic.
            .setRecurring(true)
           // Run between 30 - 60 seconds from now.
            .setTrigger(Trigger.executionWindow(0, 0))
            .setRetryStrategy(RetryStrategy.DEFAULT_LINEAR)
            // .setTrigger(Trigger.NOW)
            //Run this job only when the network is avaiable.
            .setConstraints(Constraint.ON_ANY_NETWORK)
            .build();
    return job;
}
}

MakeService.java

package com.webappclouds.jobserviceexample;


import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.SystemClock;
import android.util.Log;


import com.firebase.jobdispatcher.JobService;

import java.util.logging.LogRecord;

import static android.content.ContentValues.TAG;

public class MakeService extends JobService {
    boolean jobintentService=false;
    Handler handler;

    @Override
    public void onCreate() {
        super.onCreate();
        handler= new Handler();
    }


    @Override
    public boolean onStartJob(com.firebase.jobdispatcher.JobParameters job) {
        Log.d(TAG, "onStartJob: ");
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Log.d(TAG, "run: Handler");
                handler.postDelayed(this,10000);
            }
        },10000);
        return true;
    }

    @Override
    public boolean onStopJob(com.firebase.jobdispatcher.JobParameters job) {
        Log.d(TAG, "onStopJob: ");
        return true;
    }

}

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.webappclouds.jobserviceexample">

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service
            android:exported="false"
            android:permission=""
            android:name=".MakeService">
            <intent-filter>
                <action android:name="com.firebase.jobdispatcher.ACTION_EXECUTE"/>
            </intent-filter>
        </service>
    </application>

</manifest>

Build (Project)

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:4.2.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Build (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.webappclouds.jobserviceexample"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.firebase:firebase-jobdispatcher:0.5.2'

}

i expect that to work, i'm not knowing what is going on.

** SOlUTION ** it is due to the version implementation 'com.firebase:firebase-jobdispatcher:0.8.5' i updated it, it working from now

Shekar
  • 11
  • 4

2 Answers2

0

The error message literally has the solution

Either update the SDK or lower your app's target SDK version. Package: com.webappclouds.jobserviceexample

Update your library from 0.5.2

implementation 'com.firebase:firebase-jobdispatcher:0.8.5'

I've also noticed you have an empty permission value on your manifest, remove it.

android:permission=""

Let me know if this helps


I would recommend you to migrate to WorkManager since it is a more backward compatible and simpler API. When using this library all your API level restrictions are taken care of (restrictions is different from security).

You can find a simple workflow example here:

And the documentation:

I recommend you read both.

Joaquim Ley
  • 4,038
  • 2
  • 24
  • 42
0

please check this official Android document about Firebase JobDispatcher here:

WorkManager is a library for scheduling and executing deferrable background work in Android. It is the recommended replacement for Firebase JobDispatcher. The following guide will walk you through the process of migrating your Firebase JobDispatcher implementation to WorkManager.

imansdn
  • 968
  • 1
  • 7
  • 17