• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Starting and activity and passing data

S12

Newbie
In my onActivityResult I have two if statements one is getting a picture from the gallery and the other is getting a picture from the camera. After I get picture uri it starts adobe creative sdk to edit the image. After i get the edited image I want to pass the edited image to another activity.

Code:
@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);
    }
 
I wouldn't pass the image in an Intent. I'd write the image to a file, and get the child Activity to read that file.
 
I wouldn't pass the image in an Intent. I'd write the image to a file, and get the child Activity to read that file.

Could you help me with my issue of saving the picture. I am using adobe photo sdk to edit my image. Documentation link(https://creativesdk.adobe.com/docs/android/#/articles/imageediting/index.html). They say use .withOutput(Uri) to save the image which i created but get my image with an error.

Code:
public void editPic(Uri uri) {

        // Create the File where the photo should go
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
        }

        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.ayyogames.photoapp.fileprovider",
                    photoFile);

            Intent intent = new AdobeImageIntent.Builder(this)
                    .setData(uri)
                    .withOutputSize(MegaPixels.Mp10)
                    .withOutputQuality(100)
                    .withOutput(photoURI)
                    .build();

            startActivityForResult(intent, IMG_CODE_EDIT);
        }
    }

Code:
private File createImageFile() throws IOException {
        // Create an image file name
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
        String imageFileName = "JPEG_" + timeStamp + "_";
        File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
        File image = File.createTempFile(
                imageFileName,  /* prefix */
                ".jpg",         /* suffix */
                storageDir      /* directory */
        );

        // Save a file: path for use with ACTION_VIEW intents
        mCurrentPhotoPath = "file:" + image.getAbsolutePath();
        return image;
    }
 
Last edited:
And the error is......?!
Theres no error but it saves the images like the one attached. I seems my code is working well I dont know what the issue is. the images are being saved a cached photos.
 

Attachments

  • Screenshot_2016-07-02-03-57-25[1].png
    Screenshot_2016-07-02-03-57-25[1].png
    30.6 KB · Views: 140
Last edited:
What's the exception? As it stands, this code just discards it, so you have no idea what the exception is.

Code:
catch (IOException ex) {

          // Error occurred while creating the File
}
 
What's the exception? As it stands, this code just discards it, so you have no idea what the exception is.

Code:
catch (IOException ex) {

          // Error occurred while creating the File
}

the exception toast to the user that there is an error has occurred. But the code doesnt throw an exception.
 
How do you know it doesn't throw an exception?

it would toast my error righr? or their would be some other type of error with the app running. I'm still new to the android development i'm learning these stuff on the go.
 
If you want to learn then listen to what I'm saying. You posted the following code

Code:
try {
            photoFile = createImageFile();
}
catch (IOException ex)
           // Error occurred while creating the File
}

Having a blank catch block is one of the dumbest things you can do in Java, because should an Exception be thrown, then your code will do absolutely nothing with it, and you won't know anything about it.

So in the above, createImageFile() could actually be throwing an Exception.

If you're catching an Exception, and want to know about it, then either log an error, or re-throw the Exception.
 
If you want to learn then listen to what I'm saying. You posted the following code

Code:
try {
            photoFile = createImageFile();
}
catch (IOException ex)
           // Error occurred while creating the File
}

Having a blank catch block is one of the dumbest things you can do in Java, because should an Exception be thrown, then your code will do absolutely nothing with it, and you won't know anything about it.

So in the above, createImageFile() could actually be throwing an Exception.

If you're catching an Exception, and want to know about it, then either log an error, or re-throw the Exception.
Updated code. Its just saving the images as cached photos.
Code:
try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Log.d(TAG, "Error", ex);
            Toast.makeText(this,"Error has occured",Toast.LENGTH_LONG).show();
        }
 
Back
Top Bottom