@RequiresApi(api = Build.VERSION_CODES.M)标签:permissionName,动态,Log,批量,复选框,packageManager,权限,permissions From: https://www.cnblogs.com/a-n-yan/p/17301844.html
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main)
PackageManager packageManager = this.getPackageManager();
PermissionInfo permissionInfo = null;
for (int i = 0; i < permissions.length; i++) { //批量申请权限
try {
permissionInfo = packageManager.getPermissionInfo(permissions[i], 0);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
CharSequence permissionName = permissionInfo.loadLabel(packageManager);
if (ContextCompat.checkSelfPermission(this, permissions[i]) != PackageManager.PERMISSION_GRANTED){
// 未获取权限
Log.d("oy", "您未获得【" + permissionName + "】的权限 ===>");
if (ActivityCompat.shouldShowRequestPermissionRationale(this, permissions[i])){
// 这是一个坑,某些手机弹出提示时没有永不询问的复选框,点击拒绝就默认勾上了这个复选框,而某些手机上即使勾选上了永不询问的复选框也不起作用
Log.d("oy", "您勾选了不再提示【" + permissionName + "】权限的申请");
} else {
ActivityCompat.requestPermissions(this, permissions, MY_REQUEST_CODE);
}
} else {
Log.d("oy", "您已获得了【" + permissionName + "】的权限");
dyInterfaceImp.getTTDataStatus(this);
/*wifi状态*/
dyInterfaceImp.getWifiStatus(this);
dyInterfaceImp.getDeviceInfo(this);
}
}
}