gpt4 book ai didi

android - Caused by : java. lang.SecurityException: "gps"location provider requires ACCESS_FINE_LOCATION 权限

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:14:38 26 4
gpt4 key购买 nike

我已经设置了权限。为什么我仍然收到此错误?

Caused by: java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission.

我的 list 内容:

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

我的 Activity 代码:

    public class LocationActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_location);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}




/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {

private LocationManager mLocationManager;

public PlaceholderFragment() {
}

private final LocationListener locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());

}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {

}

@Override
public void onProviderEnabled(String provider) {

}

@Override
public void onProviderDisabled(String provider) {

}
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_location, container, false);

mLocationManager = (LocationManager) getActivity().getSystemService(LOCATION_SERVICE);

mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, locationListener);

return rootView;
}
}
}

最佳答案

您的 targetSdkVersion 是什么?

On your apps that target Android 6.0 (API level 23) or higher, make sure to check for and request permissions at runtime. To determine if your app has been granted a permission, call the new checkSelfPermission() method. To request a permission, call the new requestPermissions() method. Even if your app is not targeting Android 6.0 (API level 23), you should test your app under the new permissions model. : From Android Site

在 Android 6.0 Marshmallow 中,应用程序在安装时不会被授予任何权限。相反,应用程序必须在运行时逐一询问用户权限仅当应用程序目标级别为 23 时

旧版本:
如果应用程序的 targetSdkVersion 设置为小于 23。将假定应用程序尚未使用新的权限系统进行测试,并将切换到相同的旧行为:用户必须在安装时接受每一个权限,并且它们将全部被授予一旦安装!

关于android - Caused by : java. lang.SecurityException: "gps"location provider requires ACCESS_FINE_LOCATION 权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26625363/

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