Разрешить URI от PickVisualMediaRequest к абсолютному пути в Android 14JAVA

Программисты JAVA общаются здесь
Anonymous
Разрешить URI от PickVisualMediaRequest к абсолютному пути в Android 14

Сообщение Anonymous »

В Android 14 обратный вызов PickVisualMediaRequest возвращает абстрактный URI, который не указывает на изображение и не может быть разрешено в управлении HTML -файлом WebView. PickVisualMediaRequest обратный вызов к абсолютному пути? Есть ли альтернативный подход? /> sdcard/.transforms/synthetic/picker/0/com.android.providers.media.photopicker/media/1000000030.jpg
// Android 14
ActivityResultLauncher
pickMedia =
registerForActivityResult(new ActivityResultContracts.PickVisualMedia(), uri -> {
String newUri = getPathFromURI(uri);

Uri[] results = new Uri[]{Uri.parse(newUri)};
mUMA.onReceiveValue(results);
mUMA = null;
});
< /code>
webView.setWebChromeClient(new WebChromeClient() {
public boolean onShowFileChooser(WebView webView, ValueCallback filePathCallback, FileChooserParams fileChooserParams) {
pickMedia.launch(new PickVisualMediaRequest.Builder()
.setMediaType(ActivityResultContracts.PickVisualMedia.ImageOnly.INSTANCE)
.build());

return true;
}
});

< /code>
public String getPathFromURI(Uri contentUri) {
String res = null;
String[] proj = { MediaStore.Images.Media.DATA };
ContentResolver contentResolver = this.getContentResolver();

Cursor cursor = contentResolver.query(contentUri, proj, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
res = cursor.getString(column_index);
}
if (cursor != null) {
cursor.close();
}
return res;
}
< /code>
I am trying to retrieve an image from an Android devices and set the image path to a webview html upload control. This was the existing behavior before Andriod 14.


Подробнее здесь: https://stackoverflow.com/questions/795 ... android-14

Вернуться в «JAVA»