Android Simple call system camera and album

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.