Cannot resolve Manifest.permission.ACCESS_FINE_LOCATION

前端 未结 12 979
天涯浪人
天涯浪人 2020-12-04 23:13

When adding permissions to my manifest file, the below xml works.

 
相关标签:
12条回答
  • 2020-12-04 23:48

    if you are working on dynamic permissions and any permission like ACCESS_FINE_LOCATION,ACCESS_COARSE_LOCATION giving error "cannot resolve method PERMISSION_NAME" in this case write you code with permission name and then rebuild your project this will regenerate the manifest(Manifest.permission) file

    0 讨论(0)
  • 2020-12-04 23:49
     if (Build.VERSION.SDK_INT >= 23) {
    
                if (checkSelfPermission(android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
                        || checkSelfPermission(android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
    
                    mapView.setMyLocationEnabled(true); 
                }
            }
            else
            {
                mapView.setMyLocationEnabled(true);
    
            }
    
    0 讨论(0)
  • 2020-12-04 23:50

    For the first part, you should be using <uses-permission> according the the Android Devlopers site. Try making sure you declare your permissions directly under the <manifest> tag, not in your <application> tag. It's hard to know what your problem is without seeing your entire manifest file. Check out the link I posted above for more info on how to declare permissions in your manifest.

    In regards to your runtime permissions problem:

    With uses-permissions Cannot resolve that..

    new String[]{Manifest.permission.ACCESS_FINE_LOCATION}

    Why?

    Make sure you're using android.Manifest instead of my.app.package.Manifest. A lot of times Android Studio will default to the latter instead of the former.

    So, your new line of code would look like:

    new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION};
    

    Edit: I reformatted my answer.

    Edit 2: Be wary of importing android.Manifest. It can cause issues if you're also importing my.app.package.Manifest. Other than that import android.Manifest is another valid way to resolve this issue.

    0 讨论(0)
  • 2020-12-04 23:52

    Try this! Since ACCESS_FINE_LOCATION available in following package so Add:

    import android.Manifest;
    

    ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­

    0 讨论(0)
  • 2020-12-04 23:55

    change this

    Manifest.permission.ACCESS_FINE_LOCATION

    into this

    android.Manifest.permission.ACCESS_FINE_LOCATION

    0 讨论(0)
  • 2020-12-04 23:55

    If you have already the uses.permissions setup correctly in your manifest file, as already mentioned by hnilsen, just replace your line:

     Manifest.permission.ACCESS_FINE_LOCATION
    

    by this one:

     android.Manifest.permission.ACCESS_FINE_LOCATION
    

    This can solve your problem.

    0 讨论(0)
提交回复
热议问题