gpt4 book ai didi

android - ActivityCompat.requestPermissions

转载 作者:行者123 更新时间:2023-12-03 16:53:01 36 4
gpt4 key购买 nike

当我的Activity来电ActivityCompat.requestPermissions ,不出现 UI 对话框。

ActivityCompat.requestPermissions(HomeActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);

我在手机上有这个屏幕:

Setup program stopped windows

我不知道该怎么做,我尝试:
requestPermissions( new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);

我有相同的结果,如果我将这一行放在注释中并且我没有出现的窗口但我没有结果(UI 对话框)

最佳答案

尝试这个:

 ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);

还要确保在 list 中你有这个:
 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

获得许可结果:
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
}
}

关于android - ActivityCompat.requestPermissions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41449652/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com