Commit aa91bb6f by Simhachalam ch

changed service to Job Service to avoid crash in android 8.0 versions

parent 708eda49
...@@ -36,7 +36,7 @@ android { ...@@ -36,7 +36,7 @@ android {
defaultConfig { defaultConfig {
applicationId "com.vsoft.vera" applicationId "com.vsoft.vera"
minSdkVersion 21 minSdkVersion 23
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "0.0.1" versionName "0.0.1"
...@@ -72,7 +72,7 @@ android { ...@@ -72,7 +72,7 @@ android {
vportal { vportal {
applicationId "com.vsoft.vera.vportal" applicationId "com.vsoft.vera.vportal"
versionCode 1 versionCode 1
versionName "1.1.0" versionName "0.2.1"
} }
} }
} }
......
...@@ -88,7 +88,8 @@ ...@@ -88,7 +88,8 @@
android:screenOrientation="portrait" /> android:screenOrientation="portrait" />
<activity android:name=".ui.InAppWebViewActivity" /> <activity android:name=".ui.InAppWebViewActivity" />
<service android:name=".service.SyncService" /> <service android:name=".service.SyncService"
android:permission="android.permission.BIND_JOB_SERVICE" />
<provider <provider
android:name="android.support.v4.content.FileProvider" android:name="android.support.v4.content.FileProvider"
......
package com.vsoft.vera; package com.vsoft.vera;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
...@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -45,10 +48,11 @@ public class CatalogueApplication extends MultiDexApplication {
String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION); String action = intent.getStringExtra(Constants.APPLICATION_BROADCAST_DATA_ACTION);
Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: " + action); Log.d(Constants.TAG, "CatalogueApplication: onReceive: action: " + action);
if (Constants.ACTION_SYNC.equals(action)) { if (Constants.ACTION_SYNC.equals(action)) {
Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class); //Intent syncMatchSummaryIntentIntent = new Intent(context, SyncService.class);
if (Constants.DEBUG) if (Constants.DEBUG)
Log.d(Constants.TAG, "CatalogueApplication: Start SyncService"); Log.d(Constants.TAG, "CatalogueApplication: Start SyncService");
context.startService(syncMatchSummaryIntentIntent); //context.startService(syncMatchSummaryIntentIntent);
scheduleJob(context);
} }
} }
}; };
...@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication { ...@@ -75,6 +79,20 @@ public class CatalogueApplication extends MultiDexApplication {
} }
}; };
// schedule the start of the service every 10 - 30 seconds
public static void scheduleJob(Context context) {
ComponentName serviceComponent = new ComponentName(context, SyncService.class);
JobInfo.Builder builder = new JobInfo.Builder(0, serviceComponent);
builder.setMinimumLatency(1 * 1000); // wait at least
builder.setOverrideDeadline(3 * 1000); // maximum delay
//builder.setRequiredNetworkType(JobInfo.NETWORK_TYPE_UNMETERED); // require unmetered network
//builder.setRequiresDeviceIdle(true); // device should be idle
//builder.setRequiresCharging(false); // we don't care if the device is charging or not
JobScheduler jobScheduler = context.getSystemService(JobScheduler.class);
jobScheduler.schedule(builder.build());
}
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
......
package com.vsoft.vera.service; package com.vsoft.vera.service;
import android.app.IntentService; import android.app.IntentService;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Intent; import android.content.Intent;
import android.os.AsyncTask;
import com.vsoft.vera.CatalogueApplication; import com.vsoft.vera.CatalogueApplication;
import com.vsoft.vera.api.listeners.get.GetChatServerApiListener; import com.vsoft.vera.api.listeners.get.GetChatServerApiListener;
...@@ -62,29 +65,45 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI ...@@ -62,29 +65,45 @@ import static com.vsoft.vera.db.managers.CatalogueItemInputManager.getDirtyItemI
*/ */
public class SyncService extends IntentService { public class SyncService extends JobService {
private SyncStatus syncStatus = SyncStatus.FAIL; private SyncStatus syncStatus = SyncStatus.FAIL;
public SyncService() { @Override
super(SyncService.class.getSimpleName()); public boolean onStartJob(JobParameters params) {
BackgroundQueueAsync backgroundQueueAsync = new BackgroundQueueAsync();
backgroundQueueAsync.execute();
return false;
} }
@Override @Override
protected void onHandleIntent(Intent intent) { public boolean onStopJob(JobParameters params) {
CatalogueApplication application = (CatalogueApplication) getApplication(); return false;
if (!application.isNetConnected()) { }
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit."); public class BackgroundQueueAsync extends AsyncTask<Void, Void, Void> {
return; public BackgroundQueueAsync() {
} }
if(Util.isChatItemEnabled()) { @Override
if (application.getSocket() == null) { protected Void doInBackground(Void... voids) {
getChatServerUrl();
CatalogueApplication application = (CatalogueApplication) getApplication();
if (!application.isNetConnected()) {
CatalogueLog.e("SyncService: onHandleIntent(): Not connected to net. Exit.");
}else{
if(Util.isChatItemEnabled()) {
if (application.getSocket() == null) {
getChatServerUrl();
}
}
startSync();
} }
}
startSync();
return null;
}
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment