本文整理汇总了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;
}