5

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)

Paul Roub
  • 35,848
  • 27
  • 79
  • 88
JPrioul
  • 51
  • 1
  • 1
  • 3
  • 2
    Use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Jan 03 '17 at 18:11
  • The application does not crash, I just have the message, after the application works properly (juste i dont have the UI for the Permissions) . – JPrioul Jan 03 '17 at 19:23
  • That message would indicate that your app crashed, if I am translating the message properly. I suggest that you double-check LogCat. – CommonsWare Jan 03 '17 at 19:47
  • I have nothing in the logcat only information and verbose – JPrioul Jan 03 '17 at 20:16

1 Answers1

3

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
    }
}
rafsanahmad007
  • 23,761
  • 6
  • 46
  • 59