onRequestPermissionsResult returns immediately with denied permission

前端 未结 2 2026
故里飘歌
故里飘歌 2021-01-18 04:24

My Android app needs to request permission for location services. I do this with:

ActivityCompat.requestPermissions(this, new String[]{
                              


        
相关标签:
2条回答
  • 2021-01-18 04:27

    Change:

    <uses-permission android:name="android.permission.ACCESS_COURSE_LOCATION"/>
    

    to:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    

    The permission is for "coarse" location data (i.e., not fine-grained), not "course" location data (e.g., where some university class is being held).

    0 讨论(0)
  • 2021-01-18 04:38
    private int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 100;  
    private void checkPermission() {
         if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION)
                 != PackageManager.PERMISSION_GRANTED) {
              requestPermissions(newString[{Manfest.permission.ACCESS_COARSE_LOCATION},
                      PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION);
          } else {
              doShowLocation();
          }
      }
    
      @Override
      public void onRequestPermissionsResult(int requestCode, String[] permissions,
              int[] grantResults) {
          if (requestCode == PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION
                  && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
              showContacts();
         }
      }
    
    0 讨论(0)
提交回复
热议问题