List of usage examples for android.content.pm PackageManager GET_PERMISSIONS
int GET_PERMISSIONS
To view the source code for android.content.pm PackageManager GET_PERMISSIONS.
Click Source Link
From source file:Main.java
public static PackageInfo loadPackageInfo(PackageManager mPm, String packageName) { try {/*from w w w. j ava2s . co m*/ return mPm.getPackageInfo(packageName, PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS); } catch (NameNotFoundException e) { return null; } }
From source file:Main.java
public static PackageInfo getApkInfo(Context context, String pkg) { PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = null;/* ww w .ja v a 2 s . c o m*/ try { pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_PERMISSIONS); } catch (NameNotFoundException e) { e.printStackTrace(); } return pkgInfo; }
From source file:Main.java
public static boolean hasPermissionInManifest(Context context, String permissionName) { final String packageName = context.getPackageName(); try {// w w w. j a v a 2s. c o m final PackageInfo packageInfo = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); final String[] declaredPermisisons = packageInfo.requestedPermissions; if (declaredPermisisons != null && declaredPermisisons.length > 0) { for (String p : declaredPermisisons) { if (p.equals(permissionName)) { return true; } } } } catch (PackageManager.NameNotFoundException e) { } return false; }
From source file:Main.java
public static List<String> getAppPermissions(Context context, String packageName) { try {/* w ww. ja v a 2s . c o m*/ PackageInfo info = context.getPackageManager().getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); return Arrays.asList(info.requestedPermissions); } catch (Exception e) { e.printStackTrace(); } return new ArrayList<>(); }
From source file:Main.java
public static List<String> getAppPermission(Context mContext, String packageName) { List<String> mList = new ArrayList<>(); try {/*from w w w . jav a 2 s . c om*/ PackageManager pm = mContext.getPackageManager(); PackageInfo pack = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); String[] permissionStrings = pack.requestedPermissions; if (permissionStrings != null) { for (int i = 0; i < permissionStrings.length; i++) { mList.add(permissionStrings[i]); } } return mList; } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return mList; }
From source file:Main.java
public static void hasPermission() { if (mContext == null) throw new NullPointerException("you must initialize in appliction to use: CCCoreUtil.init"); PackageManager pm = mContext.getPackageManager(); PackageInfo pInfo = null;/* w ww . j av a 2 s. com*/ try { pInfo = pm.getPackageInfo(mContext.getPackageName(), PackageManager.GET_PERMISSIONS); String[] permissions = pInfo.requestedPermissions; for (String permission : permissions) { if (TextUtils.equals(mContext.getPackageName() + ".permission." + "WANG_CC_CONG", permission)) return; } } catch (Exception e) { // TODO: handle exception System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); } System.out.print("Authentication failed, you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKAGENAME.permission.WANG_CC_CONG\" />"); throw new RuntimeException("you must register WANG_CC_CONG permission like:" + " <uses-permission android:name=\"PACKNAME.permission.WANG_CC_CONG\" />"); }
From source file:Main.java
/** * get all <uses-permission> tags included under <manifest> * /*from ww w .j av a 2 s . com*/ * @param context */ public static void getAllAppPermissions(Context context) { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo; try { // Array of all <uses-permission> tags included under <manifest>, or // null if there were none. packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS); String permissions[] = packageInfo.requestedPermissions; if (permissions != null) { // to list permission for (String permission : permissions) { Log.i("4A", "permission:" + permission); } } } catch (NameNotFoundException e) { e.printStackTrace(); } }
From source file:Main.java
/** * Get app permission//from w w w . ja va 2 s. c om * * @param context * @param packageName * @return */ public static String[] getAppPermission(Context context, String packageName) { try { PackageManager pm = context.getPackageManager(); PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); return packageInfo.requestedPermissions; } catch (NameNotFoundException e) { e.printStackTrace(); } return null; }
From source file:Main.java
public static List<String> findMaliciousPackages(Context context) { List<String> maliciousApps = new ArrayList<String>(); List<PackageInfo> installedApps = context.getPackageManager() .getInstalledPackages(PackageManager.GET_PERMISSIONS); for (PackageInfo pkg : installedApps) { int result = isPackageMalicious(context, pkg); if (result != 0) { maliciousApps.add(pkg.packageName + ":" + result); }//from www.ja v a 2s. com } return maliciousApps; }
From source file:Main.java
public static void printAllPermission(Context context) { if (!debug) { return;//www .j a v a 2 s .c o m } PackageManager pm = context.getPackageManager(); CharSequence csPermissionGroupLabel; CharSequence csPermissionLabel; List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.GET_PERMISSIONS); for (PermissionGroupInfo pgi : lstGroups) { csPermissionGroupLabel = pgi.loadLabel(pm); Log.d("ldx", "PermissionGroup: " + pgi.name + " [" + csPermissionGroupLabel.toString() + "]"); try { List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0); for (PermissionInfo pi : lstPermissions) { csPermissionLabel = pi.loadLabel(pm); Log.d("ldx", " PermissionChild" + pi.name + " [" + csPermissionLabel.toString() + "]"); } } catch (Exception ex) { ex.printStackTrace(); } } }