gpt4 book ai didi

要使用的 Android 位置管理器权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:15:49 25 4
gpt4 key购买 nike

我的android项目中有以下代码:

locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
bestProvider = locationManager.getBestProvider(criteria, false);
Location currentLocation = locationManager.getLastKnownLocation(bestProvider);
location = currentLocation.getLatitude() + " " + currentLocation.getLongitude();
MyLocation.setText(location);

我收到一个 provider == null 错误。我需要使用什么权限?

我的 android list 文件是:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.DuckTag"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".DuckTagActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

</application>
</manifest>

谢谢

最佳答案

这是您需要添加到 list 文件中的内容

基于 GPS 的位置

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

基于网络的位置

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

以前的发贴者是错误的,如果你想同时使用两者,那么只需要ACCESS_FINE_LOCATION,详见此处:http://developer.android.com/guide/topics/location/obtaining-user-location.html

Note: If you are using both NETWORK_PROVIDER and GPS_PROVIDER, then you need to request only the ACCESS_FINE_LOCATION permission, because it includes permission for both providers. (Permission for ACCESS_COARSE_LOCATION includes permission only for NETWORK_PROVIDER.

关于要使用的 Android 位置管理器权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6899988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com