List of usage examples for android.content Context checkCallingOrSelfPermission
@CheckResult(suggest = "#enforceCallingOrSelfPermission(String,String)") @PackageManager.PermissionResult public abstract int checkCallingOrSelfPermission(@NonNull String permission);
From source file:Main.java
public static boolean checkPermission(Context context, String permission) { return context.checkCallingOrSelfPermission(permission) == 0 ? true : CLS_TRACE_DEFAULT; }
From source file:Main.java
public static boolean hasVibratePermission(Context context) { int res = context.checkCallingOrSelfPermission(Manifest.permission.VIBRATE); return (res == PackageManager.PERMISSION_GRANTED); }
From source file:Main.java
public static boolean hasPermission(Context context, String permission) { return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
public static boolean isPermissionEnabled(Context paramContext, String paramString) { return paramContext.checkCallingOrSelfPermission("android.permission." + paramString) == 0; }
From source file:Main.java
@SuppressWarnings("MissingPermission") public static String[] getGoogleAccounts(Context ctx) { if (ctx.checkCallingOrSelfPermission( Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED) { Account[] accounts = AccountManager.get(ctx).getAccountsByType("com.google"); String[] result = new String[accounts.length]; for (int i = 0; i < accounts.length; i++) { result[i] = accounts[i].name; }/* w w w .ja v a 2s . c o m*/ return result; } return null; }
From source file:Main.java
public static boolean checkPermission(Context context, String permission) { int res = context.checkCallingOrSelfPermission(permission); return (res == PackageManager.PERMISSION_GRANTED); }
From source file:Main.java
public static boolean checkPermission(@NonNull Context context, @NonNull String permission) { return context.checkCallingOrSelfPermission(permission) == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
/** * Function for check the network connectivity * //w ww. ja v a 2s. co m * @return true if network Available otherwise false */ public static boolean isNetworkAvailable(Context context) { if (context .checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) { return false; } ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connMgr.getActiveNetworkInfo(); return netInfo != null && netInfo.isConnected(); }
From source file:Main.java
private static boolean hasExternalStoragePermission(Context context) { int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION); return perm == PackageManager.PERMISSION_GRANTED; }
From source file:Main.java
public static String getGpsEnabled(Context context) { if (PackageManager.PERMISSION_GRANTED == context .checkCallingOrSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)) { final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); return Boolean.toString(manager.isProviderEnabled(LocationManager.GPS_PROVIDER)); } else {//from www . ja v a 2 s .c om return null; } }