问题描述
我正在更新我的应用程序贾夫纳神庙.使其可以支持Android M设备(v 6.0及更高版本).
Hi i am updating my application jaffna Temples . so that it can support Android M devices (v 6.0 and above).
有没有一种方法可以一次请求多个权限.例如:我想获得同时读取手机状态和位置信息的权限.
Is there a way i can request multiple permission at a single time.eg: I want to get the permission to read phone state and location information at the same time.
使用这种方式,我可以一个一个地请求权限.但是我想在应用程序启动时立即保留这两个权限.
Using this ways i can request permission one by one. But i want to rest both permission at once at the start of the application.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (checkSelfPermission(Manifest.permission.READ_PHONE_STATE)
!= PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE},
PERMISSIONS_REQUEST_READ_PHONE_STATE);
} else {
setPhoneDetails();
}
}
请给我一些建议. Tnx.
Please give me some suggestions. Tnx.
推荐答案
在要传递给requestPermissions()
的String[]
中放置多个权限.
Put more than one permission in the String[]
that you are passing to requestPermissions()
.
例如,在此示例项目中,我会静态定义权限集合,例如:
For example, in this sample project, I define collections of permissions statically, such as:
private static final String[] PERMS_TAKE_PICTURE={
CAMERA,
WRITE_EXTERNAL_STORAGE
};
以便我以后可以请求这些权限:
so that I can request those permissions later:
ActivityCompat.requestPermissions(this, PERMS_TAKE_PICTURE,
RESULT_PERMS_INITIAL);
这篇关于Android M一次请求多个权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!