0

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;
  • "update the app without asking user" - very. bad. idea. Would make me uninstall immediately and report to Google. – Fildor Jan 20 '16 at 10:16
  • sir you have mistaken me actually after asking through alert to update or not then I want it to auto update the rest thing @Fildor – Hari Mohan Mehta Jan 20 '16 at 11:04
  • 1
    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 Jan 20 '16 at 11:06
  • [Android Developer Site](http://developer.android.com/training/basics/data-storage/files.html) always is a very good source for such information. – Fildor Jan 20 '16 at 11:08
  • 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 Jan 27 '16 at 06:35
  • And what does "is not working" mean? What error message do you get? Is the new apk signed with the same key as the current version that is installed? – Gavriel Jan 27 '16 at 06:56
  • Can u show the error, it will be there in logcat. Do both the apps match the same Keys – Nidhin Prathap Feb 01 '16 at 07:36
  • I am getting error at this line InputStream is = c.getInputStream(); – Hari Mohan Mehta Feb 01 '16 at 07:48
  • it's fixed by doin c.setDoInput(true); – Hari Mohan Mehta Feb 02 '16 at 05:35

1 Answers1

0

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

  • 1
    While reviewing I was like "what are you talking about, this totally answers the question", now I look at the [review result](https://stackoverflow.com/review/low-quality-posts/20005535), and oh wow, are we devided on this :D – Max Vollmer Jun 13 '18 at 10:16