我的GPS定位应用程序出了问题我已经尝试了一切,但我无法找到解决方案(我在Android 6.0中开发),这就是问题所在:
"network" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission
这是我的XML文件:
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.READ_LOGS" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".chooseEmergency"></activity>
</application>
这是我的LocationManager代码:
LocationManager mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Localizacion Local = new Localizacion();
Local.setMainActivity(this);
mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0,
(LocationListener) Local);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
//use checkSelfPermission()
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
} else {
//simply use the required feature
//as the user has already granted permission to them during installation
}
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, 1);
public class Localizacion implements LocationListener {
MainActivity mainActivity;
public MainActivity getMainActivity() {
return mainActivity;
}
public void setMainActivity(MainActivity mainActivity) {
this.mainActivity = mainActivity;
}
@Override
public void onLocationChanged(Location loc) {
latitud = loc.getLatitude();
longitud = loc.getLongitude();
this.mainActivity.setLocation(loc);
}
@Override
public void onProviderDisabled(String provider) {//pndiente de escribir;
}
@Override
public void onProviderEnabled(String provider) {//pendiente
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
请帮助,我花了2天时间查看互联网解决方案,但对我来说没有任何作用