0
votes

on capturing image from camera in lollipop and higher versions getting the result data null on onActivityResult.

launchCamera();

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        ((MyWebViewActivity) context).fileUri = CommonUtils.getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, ((MyWebViewActivity) context).fileUri);
        ((MyWebViewActivity) context).startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);

@Override

onActivityResult(int requestCode, int resultCode, Intent data);

if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            if(fileUri!=null){
                file_path = fileUri.getPath();
                System.out.println("file-path---=" + file_path);
            }else{
                Toast.makeText(this, "Please try again", Toast.LENGTH_LONG).show();
            }
            if(!CommonUtils.isEmpty(file_path)){

            }
        } else if (resultCode == RESULT_CANCELED) {
            // "User cancelled image capture",
        } else {
            // failed to capture image
        }
    } 

getOutputMediaFileUri()

File file = getOutputMediaFile(type);
    if (file != null) {
        return Uri.fromFile(file);
    }
    return null;

getOutputMediaFile()

// External sdcard location
    File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "My Images");
    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            return null;
        }
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
    File mediaFile;
    System.out.println("mediaStorageDir==" + mediaStorageDir);
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".png");
    } else if (type == MEDIA_TYPE_VIDEO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4");
    } else {
        return null;
    }
    return mediaFile;
1
"update the app without asking user" - very. bad. idea. Would make me uninstall immediately and report to Google.Fildor
sir you have mistaken me actually after asking through alert to update or not then I want it to auto update the rest thing @FildorHari Mohan Mehta
I see. You just want to circumvent Play Store, then. User still has the ability to confirm. Is there a specific reason to avoid Play Store? (Just curious)Fildor
Android Developer Site always is a very good source for such information.Fildor
If there's no memory card, you can use this to store in your device's memory:PATH=android.os.Environment.getDataDirectory().toString()+"/data/your.package.name/Download/"Yogesh Patel

1 Answers

0
votes

It appears like you're starting the activity for result from a fragment. In that case you've to override the OnActivityResult() method in both the fragment and the Activity. Check out this answer. This should help https://stackoverflow.com/a/21826858/7659504