【问题标题】:No Activity found to handle Intent : android.intent.action.EDIT没有找到处理 Intent 的活动:android.intent.action.EDIT
【发布时间】:2021-11-24 14:04:57
【问题描述】:

我想在选择图像或通过相机拍摄后打开裁剪意图。

画廊:

Intent cropIntent = new Intent("android.intent.action.EDIT");
        cropIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        cropIntent.setDataAndType(file, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, CROP_PIC);

相机:

  Intent cropIntent = new Intent("android.intent.action.EDIT");
        cropIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        File file = new File(filePath);
        Log.i("checker", "does " + file.getAbsolutePath() + " exist ?" + file.exists());
        Uri uri = Uri.fromFile(file);
        cropIntent.setDataAndType(uri, "image/*");
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        cropIntent.putExtra("return-data", true);
        startActivityForResult(cropIntent, CROP_PIC);

它适用于大多数设备,但在 Galaxy Tab A (Android 11.0) 打开编辑意图时它会给出 例外:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.EDIT dat=content://media/external/images/media/356 typ=image/* flg=0x1 (has extras) }

我正在使用此编辑意图,尽管裁剪意图就足够了,因为在 Galaxy Tab A 上,当通过图库接收图像时,图像逆时针旋转 90 度不知道为什么。所以使用编辑意图,它也不起作用。

【问题讨论】:

  • Intent for crop 在 android 上从来都不是一个好主意。因为有 100 家制造商拥有 1000 种不同的相机应用,而且他们的方案不一样。最好使用自己的 Cropper。有很多很棒的开源实现。
  • @ADM 你能解释一下为什么在 android 上裁剪意图不是一个好主意吗?

标签: java android android-intent


【解决方案1】:

您可以使用图像裁剪库,请查看并使用它。

https://github.com/ArthurHub/Android-Image-Cropper

https://github.com/Yalantis/uCrop

希望对你有帮助!!

【讨论】:

    猜你喜欢
    • 2013-03-14
    • 2021-06-05
    • 1970-01-01
    • 1970-01-01
    • 2014-01-29
    • 1970-01-01
    • 2022-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多