Skip to content

Commit

Permalink
Use ContextCompat.startForegroundService().
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Sep 13, 2020
1 parent 00f9eed commit 14d89f9
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions app/src/main/java/org/schabi/newpipe/util/NavigationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import androidx.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import androidx.preference.PreferenceManager;

import com.nostra13.universalimageloader.core.ImageLoader;

Expand Down Expand Up @@ -174,7 +175,7 @@ public static void playOnPopupPlayer(final Context context, final PlayQueue queu
Toast.makeText(context, R.string.popup_playing_toast, Toast.LENGTH_SHORT).show();
final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP);
startService(context, intent);
ContextCompat.startForegroundService(context, intent);
}

public static void playOnBackgroundPlayer(final Context context,
Expand All @@ -184,7 +185,7 @@ public static void playOnBackgroundPlayer(final Context context,
.show();
final Intent intent = getPlayerIntent(context, MainPlayer.class, queue, resumePlayback);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO);
startService(context, intent);
ContextCompat.startForegroundService(context, intent);
}

public static void enqueueOnPopupPlayer(final Context context, final PlayQueue queue,
Expand All @@ -204,7 +205,7 @@ public static void enqueueOnPopupPlayer(final Context context, final PlayQueue q
final Intent intent = getPlayerEnqueueIntent(
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_POPUP);
startService(context, intent);
ContextCompat.startForegroundService(context, intent);
}

public static void enqueueOnBackgroundPlayer(final Context context, final PlayQueue queue,
Expand All @@ -220,15 +221,7 @@ public static void enqueueOnBackgroundPlayer(final Context context,
final Intent intent = getPlayerEnqueueIntent(
context, MainPlayer.class, queue, selectOnAppend, resumePlayback);
intent.putExtra(VideoPlayer.PLAYER_TYPE, VideoPlayer.PLAYER_TYPE_AUDIO);
startService(context, intent);
}

public static void startService(@NonNull final Context context, @NonNull final Intent intent) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
context.startForegroundService(intent);
} else {
context.startService(intent);
}
ContextCompat.startForegroundService(context, intent);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 14d89f9

Please sign in to comment.