android - Intent to take picture, if i press back, the application crashes -



android - Intent to take picture, if i press back, the application crashes -

i phone call function:

private void takephoto() { logservice.log(tag, "intakepicture"); intent intent = new intent(mediastore.action_image_capture); file = new file(environment.getexternalstoragedirectory().getabsolutepath() + "/blueskybio/media/", "test.jpg"); outputfileuri = uri.fromfile(file); intent.putextra(mediastore.extra_output, outputfileuri); startactivityforresult(intent, take_picture); }

which takes me on next onactivityresult:

public void onactivityresult(int requestcode, int resultcode, intent data) { if (requestcode == take_picture) { if(outputfileuri != null){ logservice.log("mainfragment", outputfileuri.tostring()); string path = outputfileuri.tostring(); selectedvideopath = path.substring(7); logservice.log("in take pic", "selectedimagepath: " + selectedvideopath); intent paintactivity = new intent(getactivity(), paintactivity.class); paintactivity.putextra("selectedimagepath", selectedvideopath); paintactivity.putextra("isvideo", false); startactivity(paintactivity); ((fragmentactivity) getactivity()).finish(); } else{ // toast.maketext(getactivity(), "no image taken", toast.length_short).show(); intent main = new intent(getactivity(), fragmentactivity.class); startactivity(main); ((fragmentactivity) getactivity()).finish(); } } }

this works ok, if phone call intent take picture, , press button, if took image before, load picture, if not, crash, because pressing back, not take picture. can escape situation?

i have tried test:

if(data != null) // instead of: if(outputfileuri != null){

but never come in "else" part of code.

use these conditions:

private static final int camera_pic_request = 1337; @override protected void onactivityresult(int requestcode, int resultcode, intent data) { super.onactivityresult(requestcode, resultcode, data); if(requestcode==camera_pic_request && resultcode == result_ok){ log.d("something","something"); } else if (resultcode == activity.result_canceled) { log.d("something","something"); }

}

android android-intent camera uri image

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -