我尝试使用 manifest.xml 中的以下代码为 Android 应用程序设置 gps 权限
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
但是当我执行时,我无法获得 gps 坐标。我收到“需要许可”的 Toast 消息。需要帮忙。这是我的代码片段。
LocationManager locationManager = (LocationManager)
getSystemService(Context.LOCATION_SERVICE);
LocationListener locationListener = new MyLocationListener();
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
Toast toast = Toast.makeText(getApplicationContext(), "no permission", Toast.LENGTH_LONG);
toast.show();
return;
}
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 5000, 10, locationListener);