Use ContextCompat.getSystemService() and the Context.getSystemService() extension function.
This commit is contained in:
parent
cdb6e718f7
commit
3da55d9f40
17 changed files with 61 additions and 43 deletions
|
|
@ -9,10 +9,9 @@ import android.os.Build;
|
|||
import android.view.KeyEvent;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import org.schabi.newpipe.App;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import static android.content.Context.BATTERY_SERVICE;
|
||||
import static android.content.Context.UI_MODE_SERVICE;
|
||||
import org.schabi.newpipe.App;
|
||||
|
||||
public final class DeviceUtils {
|
||||
|
||||
|
|
@ -30,15 +29,14 @@ public final class DeviceUtils {
|
|||
final PackageManager pm = App.getApp().getPackageManager();
|
||||
|
||||
// from doc: https://developer.android.com/training/tv/start/hardware.html#runtime-check
|
||||
boolean isTv = ((UiModeManager) context.getSystemService(UI_MODE_SERVICE))
|
||||
boolean isTv = ContextCompat.getSystemService(context, UiModeManager.class)
|
||||
.getCurrentModeType() == Configuration.UI_MODE_TYPE_TELEVISION
|
||||
|| pm.hasSystemFeature(AMAZON_FEATURE_FIRE_TV)
|
||||
|| pm.hasSystemFeature(PackageManager.FEATURE_TELEVISION);
|
||||
|
||||
// from https://stackoverflow.com/a/58932366
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
final boolean isBatteryAbsent
|
||||
= ((BatteryManager) context.getSystemService(BATTERY_SERVICE))
|
||||
final boolean isBatteryAbsent = context.getSystemService(BatteryManager.class)
|
||||
.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY) == 0;
|
||||
isTv = isTv || (isBatteryAbsent
|
||||
&& !pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package org.schabi.newpipe.util;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
@ -543,7 +545,7 @@ public final class ListHelper {
|
|||
*/
|
||||
public static boolean isMeteredNetwork(final Context context) {
|
||||
final ConnectivityManager manager
|
||||
= (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
= ContextCompat.getSystemService(context, ConnectivityManager.class);
|
||||
if (manager == null || manager.getActiveNetworkInfo() == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ import android.content.pm.ResolveInfo;
|
|||
import android.net.Uri;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.schabi.newpipe.R;
|
||||
|
||||
public final class ShareUtils {
|
||||
|
|
@ -95,7 +97,7 @@ public final class ShareUtils {
|
|||
*/
|
||||
public static void copyToClipboard(final Context context, final String text) {
|
||||
final ClipboardManager clipboardManager =
|
||||
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
ContextCompat.getSystemService(context, ClipboardManager.class);
|
||||
|
||||
if (clipboardManager == null) {
|
||||
Toast.makeText(context,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue