启动一个活动并传递uri数据



在我的onActivityResult中,我有两个if语句,一个是从图库中获取图片,另一个是从相机中获取图片。在我得到图片uri后,它启动adobe creative sdk来编辑图像。在我得到编辑过的图像后,我想开始并将编辑过的图像传递给另一个活动。

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //Gets the gallery image uri
        if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = {MediaStore.Images.Media.DATA};
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();
            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            editPic(selectedImage);
        }
        //gets Camera pic taken uri
        if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) {
            if (resultCode == RESULT_OK) {
                // Image captured and saved to fileUri specified in the Intent
                Uri mpicTaken = data.getData();
                editPic(mpicTaken);
            } else if (resultCode == RESULT_CANCELED) {
                // User cancelled the image capture
            } else {
                // Image capture failed, advise user
            }
        }
        //edited image
        Uri editedImageUri = data.getData();
        /*
            Intent intent = new Intent("com.ayyogames.photoapp.Share");
            intent.putExtra("imageUri", editedImageUri);
            startActivity(intent);
            */
    }
    public void editPic(Uri uri) {
        Intent intent = new AdobeImageIntent.Builder(this)
                .setData(uri)
                .withOutputSize(MegaPixels.Mp10)
                .withOutputQuality(100)
                .build();
        startActivityForResult(intent, IMG_CODE_EDIT);
    }

您可以将Uri存储为String,如

intent.putExtra("imageUri", editedImageUri.toString());

然后在新活动中,只需将其转换回

Uri imageUri = Uri.parse(extras.getString("imageUri"));

相关内容

  • 没有找到相关文章

最新更新