[英]ActivityCompat.requestPermissions
When my Activity
calls ActivityCompat.requestPermissions
, the UI dialog box does not appear. 当我的
Activity
调用ActivityCompat.requestPermissions
,不会出现UI对话框。
ActivityCompat.requestPermissions(HomeActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
I have this screen on the phone: 我的手机上有这个屏幕:
I do not know how to do, I try with: 我不知道该怎么办,我尝试:
requestPermissions( new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
I have the same result, if I put the line in comment and I have not the window that appears but I do not have the result (UI dialog box) 如果将行放入注释中,但没有出现的窗口,但没有结果(UI对话框),我将得到相同的结果
try this: 尝试这个:
ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
Also make sure in manifest you have this: 还要确保清单中有以下内容:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
get the result of permission in: 在以下位置获得许可的结果:
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: {
// If request is cancelled, the result arrays are empty.
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.