Android位置管理器使用权限
我的 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 清单文件是:
<?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>
谢谢
I have the following code in my android project:
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);
I am getting an provider == null
error. what permissions do I need to use?
My android manifest file is:
<?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>
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是您需要添加到清单文件中的内容
基于 GPS 的位置
基于网络的位置
之前的海报是错误的,如果您想同时使用两者,则只需要
ACCESS_FINE_LOCATION
,详细信息如下:http://developer.android.com/guide/topics/location/obtaining-user-location.htmlHere is what you need to add to your manifest file
GPS-based location
Network-based location
Previous posters are wrong, if you want to use both, then only
ACCESS_FINE_LOCATION
is required, as detailed here: http://developer.android.com/guide/topics/location/obtaining-user-location.html你需要这个
You need this
以下是您需要添加到清单文件中的内容:
用于基于 GPS 的位置或
用于基于网络的位置
如果您想构建更通用的应用程序,则可以同时需要这两者。
您好,
史蒂芬
Here is what you need to add to your manifest file :
for GPS-based location or
for network-based location
You can require both if you want to build a more versatile application.
Greetings,
Stéphane