java - How to call takePicture() method from another activity in android? -
i have main activity class have written takepicturefromcamera() method this:
public void takepicturefromcamera() { intent intent = new intent(mediastore.action_image_capture); try { string state = environment.getexternalstoragestate(); if (environment.media_mounted.equals(state)) { mimagecaptureuri = uri.fromfile(mfiletemp); } else { // solution taken here: http://stackoverflow.com/questions/10042695/how-to-get-camera-result-as-a-uri-in-data-folder mimagecaptureuri = internalstoragecontentprovider.content_uri; } intent.putextra(android.provider.mediastore.extra_output, mimagecaptureuri); intent.putextra("return-data", true); startactivityforresult(intent, request_code_take_picture); } catch (activitynotfoundexception e) { log.d("tag", "cannot take picture", e); } }
now have class doing cropping part , requirement if while cropping user feels want take picture instead of previous there want call above takepicturefromcamera() method of main activity class on button click. can me how can this. have tried doing this:
retake_button.setonclicklistener( new view.onclicklistener() { public void onclick(view v) { // setresult(result_canceled); main m = new main(); m.takepicturefromcamera(); } });
but gives me error nullpointerexception @ mimagecaptureuri = uri.fromfile(mfiletemp);
please me.
i suggest keep takepicturefromcamera()
in separate class, , call method passing activitycontext , data required it.
or else can make activity2 extend activity1
, use takepicturefromcamera()
.
Comments
Post a Comment