我正在Play商店中提交我的应用程序的更新版本(sdk 23),并且在必须在Beta测试程序中发布该部分时会出现此权限错误。
我已经使用requestPermission
对sdk 23进行了更改:
if (Utils.isMarshmallow()) {
if (ContextCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
ContextCompat.checkSelfPermission(activity, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(activity, new String[] {android.Manifest.permission.ACCESS_COARSE_LOCATION},
Utils.MY_PERMISSION_ACCESS_COARSE_LOCATION);
}
}
但要考虑使用Android sdk的设备< 23我的清单看起来像这样:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> `
我的build.gradle是:
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "br.com.app.vertz"
minSdkVersion 14
targetSdkVersion 23
versionCode 36
versionName "2.8"
}
...
仍然收到错误消息:
使用旧式权限(SDK 22及更低版本)无法将先前使用M权限(SDK 23及更高版本)的设备降级为APK。更改版本29(SDK 19)的版本32(23 SDK)时会发生这种情况。
答案 0 :(得分:2)
您还需要询问WRITE_EXTERNAL_STORAGE的运行时权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
//声明权限和请求代码
private static final String[] REQUEST_PERMISSIONS = new String[]{
Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION
};
private static final int REQUEST_PERMISSION_CODE = 007;
//检查是否需要权限
if (!checkPermission()) {
requestPermission();
} else {
//perform your task
}
private boolean checkPermission () {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return true;
}
for (String permission : REQUEST_PERMISSIONS) {
if (ActivityCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
return false;
}
}
return true;
}
private void requestPermission () {
ActivityCompat.requestPermissions(this, REQUEST_PERMISSIONS, REQUEST_PERMISSION_CODE);
}
@Override
public void onRequestPermissionsResult ( int requestCode, @NonNull String[] permissions,
@NonNull int[] grantResults){
if (requestCode == REQUEST_PERMISSION_CODE) {
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//perform your task
}
}
}
答案 1 :(得分:1)
targetSdkVersion
应为23或更高。