android - 在 "Always"对话框中选择 "Complete action using"选项时,应用程序强制关闭

标签 android image cordova crop cordova-plugins

在我的应用程序中,我需要从图库中捕获或选择图像,然后裁剪它。以下是示例屏幕截图:

Crop image with...

当选择仅一次时,它会正常工作(能够裁剪)。但当选择始终时,就会出现问题:应用强制关闭或无法加载图像

Logcat 没有显示任何错误消息(应用程序在到达 startactivity 时强制关闭)。

这是源代码:

public class CropImage extends CordovaPlugin{
    public final String ACTION_GET_IMAGE_NAME = "GetImageName";
    Uri myUri;
    int RESULT_CANCELED = 0;
    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {

        boolean result = false;
        if(action.equals(ACTION_GET_IMAGE_NAME)) {
            try {
                myUri = Uri.parse(args.getString(0));
                cropCapturedImage(myUri);
            } catch (JSONException e) {

                e.printStackTrace();
            }
            result = true;
        }


        return result;
    }

    public void cropCapturedImage(Uri picUri){

        Intent cropIntent = new Intent("com.android.camera.action.CROP");
        //indicate image type and Uri of image
        cropIntent.setDataAndType(picUri, "image/*");
        //set crop properties
        cropIntent.putExtra("crop", "true");
        cropIntent.putExtra("aspectX", 1);
        cropIntent.putExtra("aspectY", 1);
        cropIntent.putExtra("outputX", 256);
        cropIntent.putExtra("outputY", 256);
        String[] separated = String.valueOf(picUri).split("/");
        File f = new File(Environment.getExternalStorageDirectory()+"/novema/files/ski/"+separated[7]);
        cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));            
        cropIntent.putExtra("output", Uri.fromFile(f)); 
        cropIntent.putExtra("return-data", false);

        //start the activity - we handle returning in onActivityResult
        this.cordova.startActivityForResult((CordovaPlugin) this,cropIntent, 2);
    }

    public void onActivityResult(int requestCode, int resultCode, Intent intent) {

        if(resultCode != RESULT_CANCELED && intent != null){
            if(requestCode == 2){

                Bundle extras = intent.getExtras();
                //get the cropped bitmap from extras
                Bitmap thePic = extras.getParcelable("data");
            }
        }
    }

}

有什么方法可以隐藏“始终”选项吗?或者还有其他解决办法吗?

最佳答案

我设法使用上述答案解决了该问题。我所做的意味着我只是在完整操作中删除始终仅一次选项。

喜欢

 this.cordova.startActivityForResult((CordovaPlugin) this,cropIntent, 2);

这行替换成这样

this.cordova.startActivityForResult(this,Intent.createChooser(cropIntent, "Choose App to crop "), 2);

关于android - 在 "Always"对话框中选择 "Complete action using"选项时,应用程序强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25397707/

相关文章:

javascript - HTML Canvas 和 Javascript - 图像周围的阴影而不是边框

cordova InAppBrowser 不适用于 Windows 8

java - 从列表中删除项目 - 转换

android - 如何从 Sqlite 数据库中检索 DATETIME 格式

java - 存储和使用适用于 Android 的亚马逊访问 key 的安全方式

ios - Cordova 2.8.1 : camera. getPicture with photolibarary source on ios

html - 扩展 HTML5 移动应用程序以获得更多文件存储

java - Appium + Android studio -> 重复条目 : com/thoughtworks/selenium/CommandProcessor. 类

image - 将图片叠加在一张图像中

javascript - 将 JQuery 属性设置为 img src 标记中的图像文件夹路径