代码之家  ›  专栏  ›  技术社区  ›  Md Tariqul Islam

在Android 8.1.0 Mi A1中从相机和多媒体资料加载图像不工作

  •  0
  • Md Tariqul Islam  · 技术社区  · 7 年前

    我需要从照相机和画廊拍张照片。除了小米A1 Android版本8.1.0之外,我已经为其他Android设备做了完美的尝试。相机从图库中拍摄照片并裁剪它是不起作用的:“com.android.camera.action.CROP”。

    图像裁剪代码:

     private void performCrop(Uri picUri) {
            try {
    
                Intent cropIntent = new Intent("com.android.camera.action.CROP");
                //cropIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                //indicate image type and Uri
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                    cropIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    Uri contentUri = null;
                    try {
                        contentUri = FileProvider.getUriForFile(MainApplication.applicationContext, "com.kchannels.robi.circle.app.fileprovider", new File(new URI(picUri.toString())));
                    } catch (URISyntaxException e) {
                        e.printStackTrace();
                    }
                    cropIntent.setDataAndType(contentUri, "image/*");
                } else {
                    //intent.setDataAndType(Uri.fromFile(newFile), type);
                    cropIntent.setDataAndType(picUri, "image/*");
                }
    
                //set crop properties
                cropIntent.putExtra("crop", "true");
                //indicate aspect of desired crop
                //cropIntent.putExtra("aspectX", 4);
                //cropIntent.putExtra("aspectY", 3);
    
                cropIntent.putExtra("aspectX", 4);
                cropIntent.putExtra("aspectY", 4);
    
                //indicate output X and Y
                //cropIntent.putExtra("outputX", 256);
                //cropIntent.putExtra("outputY", 192);
    
                cropIntent.putExtra("outputX", 256);
                cropIntent.putExtra("outputY", 256);
    
                //cropIntent.putExtra("outputX", 768);
                //cropIntent.putExtra("outputY", );
                //retrieve data on return
                cropIntent.putExtra("return-data", true);
                //start the activity - we handle returning in onActivityResult
    
                List<ResolveInfo> list = MainApplication.applicationContext.getPackageManager().queryIntentActivities(cropIntent, 0);
    
                Intent i = new Intent(cropIntent);
                ResolveInfo res = list.get(0);
                i.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
                cropIntent = i;
                this.crop = true;
                this.cropIntent = cropIntent;
    
                return;
    
                //_a.startActivityForResult(cropIntent, PIC_CROP);
    
            } catch (ActivityNotFoundException anfe) {
                //display an error message
              //  String errorMessage = "Your device dont support crop action";
                Toast toast = Toast.makeText(_a, anfe.getMessage() , Toast.LENGTH_SHORT);
                toast.show();
            }
    

    Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                //we will handle the returned data in onActivityResult
                fileUri = getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); // store content values
                captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
                uploadfile.setFileUri(fileUri);
                startActivityForResult(captureIntent, UploadApi.CAMERA_CAPTURE);
    
    0 回复  |  直到 7 年前
    推荐文章