I have try some following solution to captured image on android version 11. But this solution are not working. when I use bitmap that time I get blur image this Is not visible properly.I have added the below code in the manifest.
android:requestLegacyExternalStorage="true" ` Add this top stored image in external storage`
<queries>
<intent>`
<action android:name="android.media.action.IMAGE_CAPTURE" />
</intent>
</queries>
// add code in class call image Intent
public static Intent getPickImageIntent(Context context) {
mContext = context;
Intent chooserIntent = null;
List<Intent> intentList = new ArrayList<>();
Intent pickIntent = new Intent(Intent.ACTION_PICK,
MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// takePhotoIntent.putExtra("return-data", true);
// takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(getTempFile(context)));
intentList = addIntentsToList(context, intentList, pickIntent);
intentList = addIntentsToList(context, intentList, takePhotoIntent);
if (intentList.size() > 0) {
chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1),
context.getString(R.string.pick_image_intent_text));
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentList.toArray(new Parcelable[]{}));
}
return chooserIntent;
}
when I add temp file path then this is not working in above API level 30
// pass image uri to activity set image in imageview
public static Uri getImageFromResultUri(Context context, int resultCode,
Intent imageReturnedIntent) {
File imageFile = getTempFile(context);
Uri selectedImage = null;
int sdkVersion = Build.VERSION.SDK_INT;
if (resultCode == Activity.RESULT_OK) {
boolean isCamera = (imageReturnedIntent == null ||
imageReturnedIntent.getData() == null ||
imageReturnedIntent.getData().toString().contains(imageFile.toString()));
if (isCamera) { /** CAMERA **/
// selectedImage = Uri.fromFile(imageFile);
Bitmap photo = (Bitmap) imageReturnedIntent.getExtras().get("data");
selectedImage = getImageUri(context,photo);
} else { /** ALBUM **/
selectedImage = imageReturnedIntent.getData();
}
}
return selectedImage;
}
when I convert Bitmap image to URI
public static Uri getImageUri(Context mContext, Bitmap inImage){
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
inImage.compress(Bitmap.CompressFormat.JPEG,100,bytes);
String path = MediaStore.Images.Media.insertImage(mContext.getContentResolver(),inImage,"Title",null);
return Uri.parse(path);
}
当我将图像位图转换为URI时,我得到了一个缩略图,所以这是一个模糊的图像,那么我如何在android版本11中不使用位图的情况下获得图像。我不知道该怎么把这张图片保存在画廊里。图像在每个设备中都变得模糊。当我使用takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(getTempFile(Context))时,这段代码在版本11以下就可以正常工作了。但是我如何在android版本11中使用相同的代码呢?
发布于 2021-03-30 10:20:40
上下文Uri.fromFile(getTempFile(Context));
您应该改用FileProvider和FileProvider.getUriForFile()来为摄影机意图提供有效的uri。
也适用于Android 11以下的版本;
发布于 2021-03-30 10:07:01
你的目标API版本是什么?requestLegacyExternalStorage
只有在最多使用Android 10的情况下才能工作,如果是targetting Android 11 you have to use Scoped Storage,则实现对此功能的支持。如果没有这个实现,你将无法在安卓11+设备上访问你的私人应用文件夹之外的文件
https://stackoverflow.com/questions/66868790
复制