diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 28cdbf020..2f215a768 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -383,7 +383,8 @@
android:exported="false" />
+ android:exported="false"
+ android:permission="android.permission.BIND_JOB_SERVICE" />
diff --git a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
index 21673942b..4ed4d1b1b 100644
--- a/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
+++ b/app/src/main/java/org/schabi/newpipe/CheckForNewAppVersion.java
@@ -1,7 +1,7 @@
package org.schabi.newpipe;
-import android.app.IntentService;
import android.app.PendingIntent;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@@ -9,6 +9,7 @@ import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import androidx.core.app.JobIntentService;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import androidx.preference.PreferenceManager;
@@ -23,14 +24,12 @@ import org.schabi.newpipe.util.ReleaseVersionUtil;
import java.io.IOException;
-public final class CheckForNewAppVersion extends IntentService {
- public CheckForNewAppVersion() {
- super("CheckForNewAppVersion");
- }
+public final class CheckForNewAppVersion extends JobIntentService {
private static final boolean DEBUG = MainActivity.DEBUG;
private static final String TAG = CheckForNewAppVersion.class.getSimpleName();
private static final String NEWPIPE_API_URL = "https://newpipe.net/api/data.json";
+ private static final int JOB_ID = -17000;
/**
* Method to compare the current and latest available app version.
@@ -147,14 +146,13 @@ public final class CheckForNewAppVersion extends IntentService {
*
* Must not be executed when the app is in background.
*/
- public static void startNewVersionCheckService() {
- final Intent intent = new Intent(App.getApp().getApplicationContext(),
- CheckForNewAppVersion.class);
- App.getApp().startService(intent);
+ public static void startNewVersionCheckService(final Context context) {
+ enqueueWork(context, CheckForNewAppVersion.class, JOB_ID,
+ new Intent(context, CheckForNewAppVersion.class));
}
@Override
- protected void onHandleIntent(@Nullable final Intent intent) {
+ protected void onHandleWork(@Nullable final Intent intent) {
try {
checkNewVersion();
} catch (final IOException e) {
diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java
index 3f0305b5f..6f1bea376 100644
--- a/app/src/main/java/org/schabi/newpipe/MainActivity.java
+++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java
@@ -176,7 +176,7 @@ public class MainActivity extends AppCompatActivity {
// Start the service which is checking all conditions
// and eventually searching for a new version.
// The service searching for a new NewPipe version must not be started in background.
- CheckForNewAppVersion.startNewVersionCheckService();
+ CheckForNewAppVersion.startNewVersionCheckService(app);
}
}
diff --git a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
index 04bad3815..46582cb24 100644
--- a/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
+++ b/app/src/main/java/org/schabi/newpipe/settings/UpdateSettingsFragment.java
@@ -33,7 +33,7 @@ public class UpdateSettingsFragment extends BasePreferenceFragment {
// Reset the expire time. This is necessary to check for an update immediately.
defaultPreferences.edit()
.putLong(getString(R.string.update_expiry_key), 0).apply();
- startNewVersionCheckService();
+ startNewVersionCheckService(getContext());
}
@Override