Example usage for android.content.pm PackageManager PERMISSION_GRANTED

List of usage examples for android.content.pm PackageManager PERMISSION_GRANTED

Introduction

In this page you can find the example usage for android.content.pm PackageManager PERMISSION_GRANTED.

Prototype

int PERMISSION_GRANTED

To view the source code for android.content.pm PackageManager PERMISSION_GRANTED.

Click Source Link

Document

Permission check result: this is returned by #checkPermission if the permission has been granted to the given package.

Usage

From source file:Main.java

@SuppressWarnings("unused")
private static boolean hasExternalStoragePermission(Context context) {
    int perm = context.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
    return perm == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

@TargetApi(value = Build.VERSION_CODES.M)
public static boolean hasNeverAskAgainPermission(Activity activity, List<String> permission) {
    for (String value : permission) {
        if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED
                && !activity.shouldShowRequestPermissionRationale(value)) {
            return true;
        }/*from w  w  w.  j  ava2  s .  c om*/
    }

    return false;
}

From source file:Main.java

public static boolean hasExternalStoragePermission(Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        return context.checkSelfPermission(
                Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
    }/*  w  w w . j a  va2s .co  m*/
    return true;
}

From source file:Main.java

private static boolean hasExternalStoragePermission() {
    int perm = mContext.checkCallingOrSelfPermission(EXTERNAL_STORAGE_PERMISSION);
    return perm == PackageManager.PERMISSION_GRANTED;
}

From source file:Main.java

public static boolean isNetworkAvailable(Context ctx) {
    int networkStatePermission = ctx.checkCallingOrSelfPermission(Manifest.permission.ACCESS_NETWORK_STATE);

    if (networkStatePermission == PackageManager.PERMISSION_GRANTED) {

        ConnectivityManager mConnectivity = (ConnectivityManager) ctx
                .getSystemService(Context.CONNECTIVITY_SERVICE);

        // Skip if no connection, or background data disabled
        NetworkInfo info = mConnectivity.getActiveNetworkInfo();
        if (info == null) {
            return false;
        }//w w w. j ava  2s  .  com
        // Only update if WiFi
        int netType = info.getType();
        // int netSubtype = info.getSubtype();
        if ((netType == ConnectivityManager.TYPE_WIFI) || (netType == ConnectivityManager.TYPE_MOBILE)) {
            return info.isConnected();
        } else {
            return false;
        }
    } else {
        return true;
    }
}

From source file:Main.java

@TargetApi(value = Build.VERSION_CODES.M)
public static List<String> findDeniedPermissions(Activity activity, String... permission) {
    List<String> denyPermissions = new ArrayList<>();
    for (String value : permission) {
        if (activity.checkSelfPermission(value) != PackageManager.PERMISSION_GRANTED) {
            denyPermissions.add(value);//from  ww w.  j  a  va 2s  .c  o  m
        }
    }
    return denyPermissions;
}

From source file:Main.java

public static String[] getNetworkState(Context pContext) {
    String[] type = new String[2];
    type[0] = "Unknown";
    type[1] = "Unknown";
    if (pContext.getPackageManager().checkPermission("android.permission.ACCESS_NETWORK_STATE",
            pContext.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) pContext
                .getSystemService("connectivity");
        if (localConnectivityManager == null)
            return type;

        NetworkInfo localNetworkInfo1 = localConnectivityManager.getNetworkInfo(1);
        if ((localNetworkInfo1 != null) && (localNetworkInfo1.getState() == NetworkInfo.State.CONNECTED)) {
            type[0] = "Wi-Fi";
            type[1] = localNetworkInfo1.getSubtypeName();
            return type;
        }/*  w  w w .  ja  v a2s .  c o  m*/
        NetworkInfo localNetworkInfo2 = localConnectivityManager.getNetworkInfo(0);
        if ((localNetworkInfo2 == null) || (localNetworkInfo2.getState() != NetworkInfo.State.CONNECTED))
            type[0] = "2G/3G";
        type[1] = localNetworkInfo2.getSubtypeName();
        return type;
    }
    return type;
}

From source file:Main.java

public static boolean checkPermission(Context context, String permission) {
    boolean result = false;
    if (Build.VERSION.SDK_INT >= 23) {
        try {//from   w w  w.j av a2  s . c o  m
            Class<?> clazz = Class.forName("android.content.Context");
            Method method = clazz.getMethod("checkSelfPermission", String.class);
            int rest = (Integer) method.invoke(context, permission);
            result = rest == PackageManager.PERMISSION_GRANTED;
        } catch (Exception e) {
            result = false;
        }
    } else {
        PackageManager pm = context.getPackageManager();
        if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
            result = true;
        }
    }
    return result;
}

From source file:Main.java

public static boolean checkPermission(Context context, String permission) {
    boolean result = false;
    if (Build.VERSION.SDK_INT >= 23) {
        try {//  w  w  w .  j  ava2 s  .  c  om
            Class<?> clazz = Class.forName("android.content.Context");
            Method method = clazz.getMethod("checkSelfPermission", String.class);
            int rest = (Integer) method.invoke(context, permission);
            if (rest == PackageManager.PERMISSION_GRANTED) {
                result = true;
            } else {
                result = false;
            }
        } catch (Exception e) {
            result = false;
        }
    } else {
        PackageManager pm = context.getPackageManager();
        if (pm.checkPermission(permission, context.getPackageName()) == PackageManager.PERMISSION_GRANTED) {
            result = true;
        }
    }
    return result;
}

From source file:Main.java

public static boolean hasPermission(Context context, String permission) {
    return context.checkPermission(permission, Process.myPid(),
            Process.myUid()) == PackageManager.PERMISSION_GRANTED;
}