ACCESS_FINE_LOCATION无法使用 [英] ACCESS_FINE_LOCATION not working

查看:2465
本文介绍了ACCESS_FINE_LOCATION无法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的 AndroidManifest.xml ...

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

<uses-sdk
    android:minSdkVersion="16"
    android:targetSdkVersion="22" />

<application
  android:name=".BeaconApp"
  android:allowBackup="true"
  android:label="@string/app_name"
  android:icon="@mipmap/ic_launcher"
  android:theme="@style/AppTheme">
  <activity
    android:name=".MainActivity"
    android:label="@string/app_name"
    android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </activity>
  <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="AIzaSyBqhOHH31FYObdzoVW9TmQsv62TOP0LSLI"/>
</application>

正如您所看到的,我添加了获取位置信息所需的适当权限。但是,当我运行我的应用程序时,出现了一个奇怪的错误......

As you can see I added the proper permissions necessary to get location info. However, when I run my app, I get a strange error...

Looks like the app doesn't have permission to access location.
Add the following line to your app's AndroidManifest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

throwLocationPermissionMissing
...etc

我已经添加了这个在我的 AndroidManifest.xml 中,为什么我会得到这个错误。我尝试重新启动Android Studio。我试图从模拟器擦除数据。我尝试了Gradle - > Clean。这些都没有帮助。这里发生了什么?

I already added this in my AndroidManifest.xml so why am I getting this error. I tried restarting Android Studio. I tried Wiping Data from emulator. I tried Gradle -> Clean. None of these helped. What is going on here?

是否有可能我的android模拟器阻止GPS或其他?

Is it possible that my android emulator is blocking GPS or something?

推荐答案

你有没有试过在运行时询问权限..

Have you tried asking permissions at runtime..

int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
    Manifest.permission.ACCESS_FINE_LOCATION);
if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
    // ask permissions here using below code
    ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
            REQUEST_CODE);
}

您可以在此网站上查看详细信息在运行时请求权限

You can check details on this site Requesting Permissions at Run Time

这是您在Android 6.0之后要求用户在运行时授予权限的方式

您可以检查 Android 6.0权限错误也回答。

希望它能帮助你。

这篇关于ACCESS_FINE_LOCATION无法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆