Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ActivityCompat.requestPermissions

Tags:

android

When my Activity calls ActivityCompat.requestPermissions, the UI dialog box does not appear.

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

I have this screen on the phone:

Setup program stopped windows

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)

like image 449
JPrioul Avatar asked Oct 18 '22 19:10

JPrioul


1 Answers

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
    }
}
like image 80
rafsanahmad007 Avatar answered Oct 21 '22 00:10

rafsanahmad007