简体   繁体   中英

Crop functionality is working on marshmallow or above but do not work below marshmallow

Image is crop and see successfully in List in marshmallow and above but not working below marshmallow. I think if we pick google photo for crop than it is working in other scenario its nont working.

Also in my situation runtime permission is already provided.

Code to click image from camera

Uri fileUri;

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File file = new File(getExternalCacheDir(), String.valueOf(System.currentTimeMillis()) + ".jpg");
    fileUri = Uri.fromFile(file);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
    startActivityForResult(intent, 501);

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {

        case 501:
            isFromOneActivityToAnother = true;
            ImageCropFunction();
            //startCropImageActivity(fileUri);
            break;

        case 502:
            uriImageListForServer.add(getImageContentUri(getApplicationContext(), new File((fileUri + "").substring(7, (fileUri + "").length()))));
            break;
    }
}

public void ImageCropFunction() {
    try {
        isFromOneActivityToAnother = true;
        Intent CropIntent = new Intent("com.android.camera.action.CROP");
        CropIntent.setDataAndType(fileUri, "image/*");
        CropIntent.putExtra("crop", "true");
        CropIntent.putExtra("outputX", 2048);
        CropIntent.putExtra("outputY", 2048);
        CropIntent.putExtra("scaleUpIfNeeded", true);
        CropIntent.putExtra("return-data", true);

        startActivityForResult(CropIntent, 502);
    } catch (ActivityNotFoundException e) {

    }
}

public static Uri getImageContentUri(Context context, File imageFile) {
    String filePath = imageFile.getAbsolutePath();
    Cursor cursor = context.getContentResolver().query(
            MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            new String[]{MediaStore.Images.Media._ID},
            MediaStore.Images.Media.DATA + "=? ",
            new String[]{filePath}, null);
    if (cursor != null && cursor.moveToFirst()) {
        int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
        cursor.close();
        return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
    } else {
        if (imageFile.exists()) {
            ContentValues values = new ContentValues();
            values.put(MediaStore.Images.Media.DATA, filePath);
            return context.getContentResolver().insert(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        } else {
            return null;
        }
    }
}

Image is crop and see successfully in List in marshmallow

No, it does not. It happens to work on the one device that you tested. Android does not have a CROP Intent . A few devices might, out of the thousands of devices on the market.

There are many image cropping libraries available for Android . Use one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM