Android ActivityCompat.requestPermissions
当myAndroid ActivityCompat.requestPermissions,android,Android,当myActivity调用ActivityCompat.requestPermissions时,UI对话框不会出现 ActivityCompat.requestPermissions(HomeActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION
Activity
调用ActivityCompat.requestPermissions
时,UI对话框不会出现
ActivityCompat.requestPermissions(HomeActivity.this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
我在手机上有一个屏幕:
我不知道如何做,我尝试:
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);
还要确保在清单中有以下内容:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
使用LogCat检查与您的崩溃相关的Java堆栈跟踪:应用程序没有崩溃,我只是在应用程序正常工作后收到消息(只是我没有权限的UI)。如果我正确翻译消息,该消息将指示您的应用程序崩溃。我建议您再次检查LogCat。我在LogCat中没有任何信息,只是详细说明了一切都已完成,它只是在请求时停止。您是否扩展..AppCompatActivity。。?请检查您的logcat是否存在特定错误。是的,我在logcat上没有特定错误。没有权限对话框,仅显示消息:“安装程序已停止”。我已经在网上找了3天了,事实上我只是复制了android网站的例子
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
}
}