@Test public void isPermissionGranted_resultFalse() { boolean result = Utils.isPermissionGranted(activity, "android.permission.ACCESS_NETWORK_STATE"); assertFalse(result); result = Utils.isPermissionGranted(activity, "android.permission.INTERNET"); assertFalse(result); result = Utils.isPermissionGranted(activity, "android.permission.WRITE_EXTERNAL_STORAGE"); assertFalse(result); }
public static boolean isPermissionGranted(@NonNull Context context, @NonNull String permission) { try { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } catch (Exception e) { return false; } }
Utils { public static boolean isPermissionGranted(@NonNull Context context, @NonNull String permission) { try { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } catch (Exception e) { return false; } } }
Utils { public static boolean isPermissionGranted(@NonNull Context context, @NonNull String permission) { try { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } catch (Exception e) { return false; } }  }
Utils { public static boolean isPermissionGranted(@NonNull Context context, @NonNull String permission) { try { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } catch (Exception e) { return false; } }  static void onUiThread(Runnable runnable); static void onUiThread(Runnable runnable, long delayMillis); static void cancelUiThreadTask(Runnable runnable); static void onBackgroundThread(Runnable runnable); static void onBackgroundThread(Runnable runnable, long delay); static void cancelBackgroundThreadTask(Runnable runnable); static String streamToString(final InputStream inputStream); @Nullable @SuppressLint("MissingPermission") static NetworkInfo getActiveNetworkInfo(@NonNull Context context); @NonNull @SuppressLint("MissingPermission") static ConnectionInfo obtainConnectionInfo(Context context); @SuppressLint("MissingPermission") static boolean isNetworkAvailable(Context context); static void getOperatorInfo(Context context, String[] outArray); @NonNull static String obtainHttpAgentString(final Context context); static String getLocalIpAddress(); @Nullable @SuppressLint("MissingPermission") static Location getLocation(Context context); static int getUtcOffsetMinutes(); @NonNull static Point getScreenSize(Context context); static float getScreenWidthInDp(Context context); static float getScreenHeightInDp(Context context); static int getScreenDpi(Context context); static float getScreenDensity(Context context); static int getScreenOrientation(Context context); static boolean isTablet(Context context); static float getBatteryLevel(Context context); static boolean canUseExternalFilesDir(Context context); static boolean isPermissionGranted(@NonNull Context context,
                                              @NonNull String permission); static byte[] getMD5(byte[] bytes); @Nullable static File getCacheDir(Context context, String dirName); static boolean isHttpUrl(String url); static String generateFileName(String url); static void close(Closeable closeable); static void flush(Flushable flushable); static boolean isViewInsideParentRect(Rect parentRect, View childView); static Rect getViewRectangle(View adView); static boolean isViewTransparent(View view); static boolean isViewHaveSize(View view); static void httpGetURL(final String url, Executor executor); static void removeViewFromParent(View view); static boolean canAddWindowToActivity(Activity activity); static void openBrowser(final Context context, String url, Executor executor, final Runnable postMethod); static String retrieveAndSaveFrame(Context context, Uri videoFileUri, String dirName); static boolean isOnTop(View view, float visibilityPercent); static void assertYear(int year); static boolean isYearValid(int year); static String getAdvertisingUUID(android.content.Context context); @SafeVarargs static Object invokeMethodByName(Object object, String methodName, Pair<Class, Object>... parameterPairs); @SafeVarargs static Object invokeMethodByName(Object object, Class<?> clazz, String methodName, Pair<Class, Object>... parameterPairs); @Nullable static T oneOf(T primary, T secondary); @Nullable static T oneOf(@Nullable T primary, @Nullable T secondary, @Nullable T otherwise); @NonNull static List<T> resolveList(@Nullable List<T> primary, @Nullable List<T> secondary); static String getAppName(android.content.Context context); static String getAppVersion(android.content.Context context); static boolean canUseCleartextTraffic(); }
Utils { public static boolean isPermissionGranted(@NonNull Context context, @NonNull String permission) { try { return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED; } catch (Exception e) { return false; } }  static void onUiThread(Runnable runnable); static void onUiThread(Runnable runnable, long delayMillis); static void cancelUiThreadTask(Runnable runnable); static void onBackgroundThread(Runnable runnable); static void onBackgroundThread(Runnable runnable, long delay); static void cancelBackgroundThreadTask(Runnable runnable); static String streamToString(final InputStream inputStream); @Nullable @SuppressLint("MissingPermission") static NetworkInfo getActiveNetworkInfo(@NonNull Context context); @NonNull @SuppressLint("MissingPermission") static ConnectionInfo obtainConnectionInfo(Context context); @SuppressLint("MissingPermission") static boolean isNetworkAvailable(Context context); static void getOperatorInfo(Context context, String[] outArray); @NonNull static String obtainHttpAgentString(final Context context); static String getLocalIpAddress(); @Nullable @SuppressLint("MissingPermission") static Location getLocation(Context context); static int getUtcOffsetMinutes(); @NonNull static Point getScreenSize(Context context); static float getScreenWidthInDp(Context context); static float getScreenHeightInDp(Context context); static int getScreenDpi(Context context); static float getScreenDensity(Context context); static int getScreenOrientation(Context context); static boolean isTablet(Context context); static float getBatteryLevel(Context context); static boolean canUseExternalFilesDir(Context context); static boolean isPermissionGranted(@NonNull Context context,
                                              @NonNull String permission); static byte[] getMD5(byte[] bytes); @Nullable static File getCacheDir(Context context, String dirName); static boolean isHttpUrl(String url); static String generateFileName(String url); static void close(Closeable closeable); static void flush(Flushable flushable); static boolean isViewInsideParentRect(Rect parentRect, View childView); static Rect getViewRectangle(View adView); static boolean isViewTransparent(View view); static boolean isViewHaveSize(View view); static void httpGetURL(final String url, Executor executor); static void removeViewFromParent(View view); static boolean canAddWindowToActivity(Activity activity); static void openBrowser(final Context context, String url, Executor executor, final Runnable postMethod); static String retrieveAndSaveFrame(Context context, Uri videoFileUri, String dirName); static boolean isOnTop(View view, float visibilityPercent); static void assertYear(int year); static boolean isYearValid(int year); static String getAdvertisingUUID(android.content.Context context); @SafeVarargs static Object invokeMethodByName(Object object, String methodName, Pair<Class, Object>... parameterPairs); @SafeVarargs static Object invokeMethodByName(Object object, Class<?> clazz, String methodName, Pair<Class, Object>... parameterPairs); @Nullable static T oneOf(T primary, T secondary); @Nullable static T oneOf(@Nullable T primary, @Nullable T secondary, @Nullable T otherwise); @NonNull static List<T> resolveList(@Nullable List<T> primary, @Nullable List<T> secondary); static String getAppName(android.content.Context context); static String getAppVersion(android.content.Context context); static boolean canUseCleartextTraffic(); static final int INDEX_CRR; static final int INDEX_OPERATOR_NAME; static final int INDEX_SIM_CRR; static final int INDEX_SIM_OPERATOR_NAME; }