[英]Android studio java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission
I am working on android studio.我正在 android 工作室工作。 I am getting live GPS coordinates on a mobile app.
我在移动应用程序上获得实时 GPS 坐标。 On every mobile device, the coordinates are generated but a single mobile is not working and giving
zero(0)
coordinates having android version 9
.在每个移动设备上,都会生成坐标,但单个移动设备无法正常工作,并给出具有 android 版本
9
的zero(0)
坐标。 Below is my code下面是我的代码
@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 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'
}
}
}
How to get rid of this issue?如何摆脱这个问题? I have been stuck for so many days Any help would be highly appreciated.
我被困了这么多天任何帮助将不胜感激。
android.permission.INSTALL_LOCATION_PROVIDER
permission falls under the system or signed permissions which means only system applications can request this permission. android.permission.INSTALL_LOCATION_PROVIDER
权限属于系统或签名权限,这意味着只有系统应用程序可以请求此权限。
Only OEMs are allowed to install a new location provider.
只允许 OEM 安装新的位置提供程序。 A third-party developer cannot grant to his/her application the permission required to install a new location provider (android.permission.INSTALL_LOCATION_PROVIDER).
第三方开发人员无法向他/她的应用程序授予安装新位置提供程序 (android.permission.INSTALL_LOCATION_PROVIDER) 所需的权限。 Read Thread
读线程
According to the documentation根据文档
Allows an application to install a location provider into the Location Manager.
允许应用程序将位置提供程序安装到位置管理器中。
Not for use by third-party applications.
不供第三方应用程序使用。
Constant Value: "android.permission.INSTALL_LOCATION_PROVIDER"
常数值:“android.permission.INSTALL_LOCATION_PROVIDER”
In order to request this permission you have to sign your app as a system app.为了请求此权限,您必须将您的应用程序签名为系统应用程序。 See How
怎么看
In order to install a new location provider either you have to root your android device or you have to develop a whole new firmware.为了安装新的位置提供程序,您必须对 android 设备进行 root,或者必须开发一个全新的固件。 Read Thread
读线程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.