ActivityCompat.requestPermissions

时间:2017-01-03 18:01:44

标签: android

当我Activity调用ActivityCompat.requestPermissions时,不显示用户界面对话框。

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对话框)

1 个答案:

答案 0 :(得分:0)

试试这个:

 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" />

获取许可结果:

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
    }
}