On Android 11 (api30) and above, media files created on external SD cards cannot be updated with MediaStore through contentResolver s insert, update, and other methods. I have written an image to the external SD card/Pictrue directory, and I want to update MediaStore immediately, but this does not work (running on Android 11 (api30) mobile platforms). I set the targetSdkVersion to 28, but it still does not work. Do any masters know why? Thank`s very much.
我对英语并不好,我希望我能够明确地表达自己的看法。
这是我的法典:
type here
java
Uri dbTable = MediaStore.Images.Media.getContentUri(MediaStore.VOLUME_EXTERNAL);
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, file.getAbsolutePath());
values.put(MediaStore.Images.Media.MIME_TYPE, "image/*");
values.put(MediaStore.Images.Media.DISPLAY_NAME, file.getName());
values.put(MediaStore.Images.Media.TITLE, getForeString(file.getName(), . ));
contentResolver.insert(dbTable, values);
我试图降低APIC的级别(API 28)。
这是我的梯度
type here
graddle
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.dc.browser"
minSdkVersion 28
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile( proguard-android-optimize.txt ), proguard-rules.pro
zipAlignEnabled true
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}