Android Studio java.lang.安全异常:需要INSTALL_LOCATION_PROVIDER权限

1sbrub3j  于 2022-12-13  发布在  Android
关注(0)|答案(1)|浏览(208)

我在android studio上工作。我在一个移动的应用程序上获得实时GPS坐标。在每个移动设备上,坐标都被生成,但一个移动设备不工作,并给出zero(0)坐标,具有android版本9。下面是我的代码

@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'
    }
}
}

如何摆脱这个问题?我已经被困了这么多天,任何帮助都将非常感谢。

tgabmvqs

tgabmvqs1#

android.permission.INSTALL_LOCATION_PROVIDER权限福尔斯系统权限或签名权限,这意味着只有系统应用程序可以请求此权限。
仅允许OEM安装新的位置提供程序。第三方开发者无法向其应用授予安装新位置提供程序所需的权限(android.permission.INSTALL_LOCATION_PROVIDER)。Read Thread
根据文件
允许应用程序将位置提供程序安装到位置管理器中。
不供第三方应用程序使用。
常数值:“Android.权限.安装位置提供者”
要请求此权限,您必须将应用签名为系统应用。See How
为了安装一个新的位置提供程序,你要么必须root你的android设备,要么你必须开发一个全新的固件。Read Thread

相关问题