public void reasonadd (VIEW V) { final string [] strs=new string[]{"Photo", "album"}; alertdialog.builder builder=new alertdialog.builder (This); builder.settitle ("photo"); Builder.setitems (Strs, new dialoginterface.onclicklistener () { @Override public void onclick (Dialoginterface dialog, int which) { //Photography can be implemented in two ways                //1. Call the System camera 2. Custom Camera      &Nbsp; if (which==0) { intent intent=new intent (mediastore.action_image_capture); startactivityforresult (intent,1); } //Call System Albums if (which==1) { intent intent=new intent (Intent.ACTION_GET_CONTENT); Intent.addcategory (intent.category_openable); intent.settype ("image/*"); Intent.putextra ("Crop", "true"); intent.putextra ("Aspectx", 1); Intent.putextra ("Aspecty", 1); intent.putextra ("Outputx", 80); intent.putextra ("Outputy", 80); intent.putextra ("Return-data", true); startactivityforresult (intent, 0); } } }); builder.show (); } // write a method to implement the camera @Override protected void onactivityresult (int Requestcode, int resultcode, intent data) { super.onactivityresult (RequestcoDe, resultcode, data); if (resultCode== ACTIVITY.RESULT_OK) { string sdstatus= environment.getexternalstoragestate (); if (!sdstatus.equals (Environment.MEDIA_MOUNTED)) {           LOG.I ("Testfile", "SD card is Not avaiable right now "); return; } String name= Calendar.getinstance (Locale.canada) + ". jpg"; &nBsp; bundle bundle=data.getextras (); FileOutputStream b=null; // to set the size of the picture and then show intent intent1=new intent (" Com.android.camera.actioin.CROP "); Intent1.putextra ("Crop", "true"); Intent1.putextra ("Outputx", +); Intent1.putextra ("Outputy", 250); Intent1.putextra ("Aspectx", 1); Intent1.putextra ("Aspecty", 1); bitmap source= (Bitmap) bundle.get ("Data"); file=new file ("/sdcard/myimage/"); file.mkdir (); string filename= "/sdcard/myimage/" +name; try { b=new fileoutputstream (Filename); source.compress ( BITMAP.COMPRESSFORMAT.JPEG,100,B); b.flush (); b.close (); } catch (FileNotFoundException e) { E.printstacktrace (); } catch (ioexception e) { e.printstacktrace (); } leave_iv_icon.setimagebitmap (source); icon=source; }else if (resultcode==0) { Bitmap cameraBitmap = (Bitmap ) data.getextras (). Get ("Data"); leave_iv_icon.setimagebitmap ( CAMERABITMAP); icon=camerabitmap; } }
This article is from the "11461798" blog, please be sure to keep this source http://11471798.blog.51cto.com/11461798/1766438
Android Simple call system camera and album