android - catch `intent not found` and call another method -
i want crop image , phone call com.android.camera.action.crop. doesn't exist on devices want have fallback grab , add together image w/o cropping.
to rename com.android.camera.action.crop xcom.android.camera.action.cropfor testing purposes , phone call in grab method resultcode no_cropbut actual resultcode pick_cropis called also.
how can ignore pick_cropin case doesn't jump drawimage()always info of course of study null , avoid null poiner exception , instead go nocrop()?
here's code:
//start cropping intent private void performcrop(int requestcode, intent data) { // take care of exceptions seek { // phone call standard crop action intent (the user device may not // back upwards it) intent cropintent = new intent("xcom.android.camera.action.crop"); // indicate image type , uri cropintent.setdataandtype(imguri, "image/*"); // set crop properties cropintent.putextra("crop", "true"); // indicate aspect of desired crop cropintent.putextra("aspectx", 1); cropintent.putextra("aspecty", 1); // indicate output x , y cropintent.putextra("outputx", 256); cropintent.putextra("outputy", 256); // retrieve info on homecoming cropintent.putextra("return-data", true); // start activity - handle returning in onactivityresult startactivityforresult(cropintent, pic_crop); } // respond users devices not back upwards crop action grab (activitynotfoundexception anfe) { // add together chosen photo straight imageview bundle extras = data.getextras(); bitmap photo = extras.getparcelable("data"); nocrop(photo, no_crop, requestcode, data); } } // draw image in circle canvas w/o crop -> fallback if crop doesn't exist on users device private void nocrop(bitmap photo, int requestcode, int resultcode, intent data) { if (requestcode == no_crop) { imageview profilepic = (imageview) findviewbyid(r.id.profilepic); graphicsutil graphicutil = new graphicsutil(); profilepic.setimagebitmap(graphicutil.getcirclebitmap(photo, 16)); saveprofile(photo); } else { super.onactivityresult(requestcode, resultcode, data); } } // draw cropped image imageview circle canvas private void drawimage(int requestcode, int resultcode, intent data) { if (requestcode == pic_crop) { bundle extras = data.getextras(); imageview profilepic = (imageview) findviewbyid(r.id.profilepic); bitmap photo = extras.getparcelable("data"); // display returned cropped image graphicsutil graphicutil = new graphicsutil(); profilepic.setimagebitmap(graphicutil.getcirclebitmap(photo, 16)); saveprofile(photo); } else { super.onactivityresult(requestcode, resultcode, data); } }
as said com.android.camera.action.crop intent not supported in devices why utilize , write fallback mechanism. there many libraries available cropping images. have used cropper , simple-image-crop library github. have @ my reply here simple-image-crop library.
android android-intent
No comments:
Post a Comment