TedImagePicker
TedImagePicker copied to clipboard
Scoped Stoarge Android 11
trafficstars
Hello, Does this lib implements migration to Scoped storage for Android 10 & 11 ?. Thanks you.
hello , did you find a solution for this ?
hey,I think this issue should be addressed now that google is enforcing use of scoped storage. Allowing legacy requests will not be working anymore.
Try to update to the latest version
implementation 'io.github.ParkSangGwon:tedimagepicker:1.2.7'
Then use the following lines of code. Checking if android is >10 and getting the Uri as follows sorted the issue
TedImagePicker.with(this)
.errorListener(new OnErrorListener() {
@OverRide
public void onError(@nonnull Throwable throwable) {
Timber.e(throwable.getMessage());
}
})
.mediaType(MediaType.IMAGE)
.start(uri -> {
File file = new File(uri.getPath());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
String[] filePathColumn = {MediaStore.MediaColumns.DATA};
Cursor cursor = App.getContext().getContentResolver().query(
uri,
filePathColumn,
null,
null,
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String absolutePathOfImage = cursor.getString(columnIndex);
if (absolutePathOfImage != null) {
Uri.parse(absolutePathOfImage);
file = new File(absolutePathOfImage);
}
cursor.close();
}
}
}
});