![](/img/trans.png)
[英]Android GoogleMaps not working on some devices shows java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission
[英]Android studio java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission
我正在 android 工作室工作。 我在移动应用程序上获得实时 GPS 坐标。 在每个移动设备上,都会生成坐标,但单个移动设备无法正常工作,并给出具有 android 版本9
的zero(0)
坐标。 下面是我的代码
@SuppressLint("MissingPermission")
public Location getLocation() {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
Gradle
android {
compileSdkVersion 33
defaultConfig {
applicationId "com.example.wrflhr.wrfnanbookings"
minSdkVersion 19
targetSdkVersion 33
versionCode 3
versionName "3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
如何摆脱这个问题? 我被困了这么多天任何帮助将不胜感激。
android.permission.INSTALL_LOCATION_PROVIDER
权限属于系统或签名权限,这意味着只有系统应用程序可以请求此权限。
只允许 OEM 安装新的位置提供程序。 第三方开发人员无法向他/她的应用程序授予安装新位置提供程序 (android.permission.INSTALL_LOCATION_PROVIDER) 所需的权限。 读线程
根据文档
允许应用程序将位置提供程序安装到位置管理器中。
不供第三方应用程序使用。
常数值:“android.permission.INSTALL_LOCATION_PROVIDER”
为了请求此权限,您必须将您的应用程序签名为系统应用程序。 怎么看
为了安装新的位置提供程序,您必须对 android 设备进行 root,或者必须开发一个全新的固件。 读线程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.