MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION permission android not recognised in code

后端 未结 1 1309
日久生厌
日久生厌 2020-12-20 00:25

We are currently trying to request GPS permissions from an android phone so that we can show the current location on a Google Map. We have included this manifest, outside of

相关标签:
1条回答
  • 2020-12-20 01:12

    you have to define it like:

    public static int MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION =1;
    

    then catch the result as:

        @Override
    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) {
    
                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.
    
                } 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
        }
    }
    
    0 讨论(0)
提交回复
热议问题