![](/img/trans.png)
[英]How to grant permission without user interaction in marshmallow for system app?
[英]How to wait for user to grant permission in Marshmallow
我有一个应用程序需要多个权限进行检查和请求,如果没有。 因此,当应用程序第一次运行时,它会跳过其后的所有函数调用,即使在单击允许访问后也是如此
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// Check Permissions Now
ActivityCompat.requestPermissions(
this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
REQUEST_CODE_LOCATION);
}
// Will not be called the first time
functionCall()
有没有办法在用户点击允许访问权限之前不调用该函数
你必须考虑像startActivityForResult
这样的requestPermissions
。 它只是启动用户授予/拒绝权限的UI。
与onActivityResult
一样,您必须覆盖onRequestPermissionsResult
以了解权限过程何时完成。 您可以检查权限是被授予还是被拒绝,并从那里执行您的逻辑。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.