本文整理匯總了Java中android.content.pm.PackageManager.getPermissionInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java PackageManager.getPermissionInfo方法的具體用法?Java PackageManager.getPermissionInfo怎麽用?Java PackageManager.getPermissionInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.getPermissionInfo方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPermissionInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* Returns information string about permission
**/
@Nullable
private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) {
context = context.getApplicationContext();
PackageManager pm = context.getPackageManager();
PermissionInfo info = null;
try {
info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException ex) {
Log.w(TAG, ex);
}
if (info != null) {
CharSequence label = info.loadLabel(pm);
if (label == null) {
label = info.nonLocalizedLabel;
}
return label.toString();
}
return null;
}
示例2: getPermissions
import android.content.pm.PackageManager; //導入方法依賴的package包/類
/**
* use for get {@link PermissionInfo} of all @param required
*
* @param context
* @param required
* @return
*/
private static List<PermissionInfo> getPermissions(Context context, List<String> required) {
List<PermissionInfo> permissionInfoList = new ArrayList<>();
PackageManager pm = context.getPackageManager();
for (String permission : required) {
PermissionInfo pinfo = null;
try {
pinfo = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
continue;
}
permissionInfoList.add(pinfo);
}
return permissionInfoList;
}
示例3: getPermissionInfo
import android.content.pm.PackageManager; //導入方法依賴的package包/類
private PermissionInfo getPermissionInfo(PackageManager packageManager, String permission) {
if (TextUtils.isEmpty(permission)) {
return null;
}
try {
return packageManager.getPermissionInfo(permission, 0);
} catch (PackageManager.NameNotFoundException e) {
UILog.w("Can't find permission " + permission, e);
return null;
}
}
示例4: getPermissionDetails
import android.content.pm.PackageManager; //導入方法依賴的package包/類
public PermissionDetails getPermissionDetails(Context context, String permission, int permissionDrawableResID) {
PackageManager pm = context.getPackageManager();
PermissionInfo info = null;
try {
info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA);
String text = info.loadDescription(context.getPackageManager()).toString();
this.permission = permission;
this.description = text;
this.protectionLevel = info.protectionLevel;
this.drawableResId = permissionDrawableResID;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return this;
}