How to use onActivityResult in activity main and in secondary activities.

0

I have the activity user, and in it I call the camera using startActivityForResult, however when taking the photo, it goes to Main Activity. How can I call the camera and return to the same user activity? Details: In Main activity, I use the startActivityForResult method to return other data. Follow camera call code in Activity User:

public void callIntentImgCam(View view){
    File file = new File(android.os.Environment.getExternalStorageDirectory(), "img.png");
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
    startActivityForResult(intent, IMG_CAM);
}

Follow return code in Activity User:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    File file = null;

    if(data != null && requestCode == IMG_SDCARD && resultCode == RESULT_OK){
        Uri img = data.getData();
        String[] cols = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(img, cols, null, null, null);
        cursor.moveToFirst();

        int indexCol = cursor.getColumnIndex(cols[0]);
        String imgString = cursor.getString(indexCol);
        cursor.close();

        file = new File(imgString);
        if(file != null){
            wd.getImage().setResizedBitmap(file, 300, 80);
            wd.getImage().setMimeFromImgPath(file.getPath());
        }
    }
    else if(requestCode == IMG_CAM && resultCode == RESULT_OK){
        file = new File(android.os.Environment.getExternalStorageDirectory(), "img.png");
        if(file != null){
            wd.getImage().setResizedBitmap(file, 80, 300);
            wd.getImage().setMimeFromImgPath(file.getPath());
        }
    }


    if(wd.getImage().getBitmap() != null){
        imageView.setImageBitmap(wd.getImage().getBitmap());
    }
}
    
asked by anonymous 15.02.2017 / 17:56

0 answers