Java 在android版本11中,摄像头意图无法正常工作 我已经尝试了以下一些解决方案来在android版本11上捕获图像。但这一解决方案并不奏效。当我使用位图的时候,我得到了模糊图像,这是不可见的。我已经在清单中添加了下面的代码。 android:requestLegacyExternalStorage=“true”`在外部存储器中添加此顶级存储的映像` ` //在类调用映像意图中添加代码 公共静态意图getPickImageIntent(上下文){ mContext=上下文; 意向选择内容=null; List intentList=new ArrayList(); 意向选择意向=新意向(意向.ACTION\u选择, MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI); Intent takePhotoIntent=新意图(MediaStore.ACTION\u IMAGE\u CAPTURE); //takePhotoIntent.putExtra(“返回数据”,true); //takePhotoIntent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(getTempFile(context)); intentList=addIntentsToList(上下文、intentList、pickIntent); 意向列表=附加内容列表(上下文、意向列表、拍摄意向); 如果(intentList.size()>0){ chooserentent=Intent.createChooser(intentList.remove(intentList.size()-1), getString(R.string.pick_image_intent_text)); 选择content.putExtra(Intent.EXTRA_INITIAL_INTENTS,intentList.toArray(新包裹[]{})); } 返回选择器内容; } 当我添加临时文件路径时,这在高于API级别30的情况下不起作用 //将图像uri传递给imageview中的活动集图像 公共静态Uri getImageFromResultUri(上下文,int resultCode, 意图(返回内容){ File imageFile=getTempFile(上下文); Uri selectedImage=null; int-sdkVersion=Build.VERSION.SDK\u int; if(resultCode==Activity.RESULT\u确定){ 布尔值isCamera=(imageReturnedIntent==null|| imageReturnedIntent.getData()==null|| imageReturnedIntent.getData().toString()包含(imageFile.toString()); 如果(isCamera){/**摄像机**/ //选择edimage=Uri.fromFile(imageFile); 位图照片=(位图)imageReturnedIntent.getExtras().get(“数据”); 选择edimage=getImageUri(上下文、照片); }else{/**相册**/ 选择edimage=imageReturnedIntent.getData(); } } 返回所选图像; } 当我将位图图像转换为URI时 公共静态Uri getImageUri(上下文mContext,位图inImage){ ByteArrayOutputStream字节=新建ByteArrayOutputStream(); inImage.compress(位图.CompressFormat.JPEG,100,字节); 字符串路径=MediaStore.Images.Media.insertImage(mContext.getContentResolver(),inImage,“Title”,null); 返回Uri.parse(路径); }

Java 在android版本11中,摄像头意图无法正常工作 我已经尝试了以下一些解决方案来在android版本11上捕获图像。但这一解决方案并不奏效。当我使用位图的时候,我得到了模糊图像,这是不可见的。我已经在清单中添加了下面的代码。 android:requestLegacyExternalStorage=“true”`在外部存储器中添加此顶级存储的映像` ` //在类调用映像意图中添加代码 公共静态意图getPickImageIntent(上下文){ mContext=上下文; 意向选择内容=null; List intentList=new ArrayList(); 意向选择意向=新意向(意向.ACTION\u选择, MediaStore.Images.Media.EXTERNAL\u CONTENT\u URI); Intent takePhotoIntent=新意图(MediaStore.ACTION\u IMAGE\u CAPTURE); //takePhotoIntent.putExtra(“返回数据”,true); //takePhotoIntent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(getTempFile(context)); intentList=addIntentsToList(上下文、intentList、pickIntent); 意向列表=附加内容列表(上下文、意向列表、拍摄意向); 如果(intentList.size()>0){ chooserentent=Intent.createChooser(intentList.remove(intentList.size()-1), getString(R.string.pick_image_intent_text)); 选择content.putExtra(Intent.EXTRA_INITIAL_INTENTS,intentList.toArray(新包裹[]{})); } 返回选择器内容; } 当我添加临时文件路径时,这在高于API级别30的情况下不起作用 //将图像uri传递给imageview中的活动集图像 公共静态Uri getImageFromResultUri(上下文,int resultCode, 意图(返回内容){ File imageFile=getTempFile(上下文); Uri selectedImage=null; int-sdkVersion=Build.VERSION.SDK\u int; if(resultCode==Activity.RESULT\u确定){ 布尔值isCamera=(imageReturnedIntent==null|| imageReturnedIntent.getData()==null|| imageReturnedIntent.getData().toString()包含(imageFile.toString()); 如果(isCamera){/**摄像机**/ //选择edimage=Uri.fromFile(imageFile); 位图照片=(位图)imageReturnedIntent.getExtras().get(“数据”); 选择edimage=getImageUri(上下文、照片); }else{/**相册**/ 选择edimage=imageReturnedIntent.getData(); } } 返回所选图像; } 当我将位图图像转换为URI时 公共静态Uri getImageUri(上下文mContext,位图inImage){ ByteArrayOutputStream字节=新建ByteArrayOutputStream(); inImage.compress(位图.CompressFormat.JPEG,100,字节); 字符串路径=MediaStore.Images.Media.insertImage(mContext.getContentResolver(),inImage,“Title”,null); 返回Uri.parse(路径); },java,android,Java,Android,当我将图像位图转换为URI时,我得到了一个缩略图,因此这是一个模糊的图像,因此如何在android版本11中不使用位图就获得图像。我不知道该在画廊里储存什么。每台设备的图像都变得模糊。 当我使用takePhotoIntent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(getTempFile(context)))时;这段代码在下面的版本11中正常工作。但是,我如何为android版本11使用相同的代码呢?android版本11是您的目标API版本reque

当我将图像位图转换为URI时,我得到了一个缩略图,因此这是一个模糊的图像,因此如何在android版本11中不使用位图就获得图像。我不知道该在画廊里储存什么。每台设备的图像都变得模糊。
当我使用takePhotoIntent.putExtra(MediaStore.EXTRA_输出,Uri.fromFile(getTempFile(context)))时;这段代码在下面的版本11中正常工作。但是,我如何为android版本11使用相同的代码呢?android版本11是您的目标API版本
requestLegacyExternalStorage
仅在针对最多Android 10时才起作用,因此实现对该功能的支持。如果没有此实现,您将无法访问Android 11+设备上私人应用文件夹之外的文件

fromFile(getTempFile(context))

您应该使用FileProvider和FileProvider.getUriForFile()来为摄影机提供有效的uri


也适用于低于Android 11的版本

我也使用了文件提供程序,但我没有得到结果。另外,我知道如何从位图bcoz中清除图像,当我将位图更改为uri时,我会得到模糊图像。请将文件提供程序代码放在帖子中。现在很难读了!我在Android 11设备的清单中添加了提供者代码,比如提供者路径。一个应用程序可以访问它在公共目录中创建的所有文件。
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);
    }