最近在做安卓源码相关项目,需要自定义安装包,其中安装的时候需要向用户展示所安装应用需要的敏感权限,按照谷歌的说法,敏感权限就那几组,这里我展示获取权限信息和图标的简要代码
private static final String[] permissions={
Manifest.permission.READ_CONTACTS,
Manifest.permission.BODY_SENSORS,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.READ_CALENDAR
};
private static final String [] permissionGroups={
Manifest.permission_group.SENSORS,
Manifest.permission_group.CALENDAR,
Manifest.permission_group.LOCATION,
Manifest.permission_group.CONTACTS,
Manifest.permission_group.ACTIVITY_RECOGNITION,
Manifest.permission_group.CAMERA,
Manifest.permission_group.MICROPHONE
};
private void initUI() {
TextView permissionDecs = findViewById(R.id.tv_desc);
ImageView permissionIcon = findViewById(R.id.iv);
PackageManager pm = getPackageManager();
PermissionInfo info;
PermissionGroupInfo groupInfo = null;
try {
// info = pm.getPermissionInfo(permissions[1], 0);
// permissionDecs.setText(info.labelRes);
// //permissionIcon.setImageDrawable(info.loadIcon(getPackageManager()));
groupInfo = pm.getPermissionGroupInfo(permissionGroups[1],0);
permissionDecs.setText(groupInfo.labelRes);
permissionIcon.setImageDrawable(groupInfo.loadIcon(getPackageManager()));
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
}
大家可以一个个去对照一下
这个是写在activity里面的代码,需要注意的是,获取图标资源不一定总是返回数据的,即使返回数据,如果手机ROM厂商没有放自己的定制图片在系统里面,可能会是一个安卓机器人的图标
|