Android Call album-camera Package

Source: Internet
Author: User

Encapsulate these two functions and use them frequently.

private static Uri photouri;public static final int NONE = 0;public static final int photohraph = 1;//camera public static fin Al int photozoom = 2; Scale public static final int photoresult = 3;//result public static final String image_unspecified = "image/*";/** * Enter camera * @ param activity */public static void Startcamera (activity activity) {Intent Intent = new Intent (mediastore.action_image_c              APTURE);//"Android.media.action.IMAGE_CAPTURE" contentvalues values = new Contentvalues ();              Photouri = Activity.getcontentresolver (). Insert (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);            Intent.putextra (Android.provider.MediaStore.EXTRA_OUTPUT, Photouri);  /**-----------------*/Activity.startactivityforresult (intent, photohraph); }/** * into albums * @param activity */public static void startphotoalbum (activity activity) {Intent Intent = new Intent (Intent.          Action_pick, NULL); Intent.setdataandtype (MediaStore.Images.Media.EXTERNAL_CONTENT_uri, image_unspecified); Activity.startactivityforresult (Intent, photozoom);} /** * Crop Photo jump system activity * @param activity * @param uri */public static void Startphotozoom (activity activity, Uri Uri) {in Tent Intent = new Intent ("Com.android.camera.action.CROP"); Intent.setdataandtype (URI, image_unspecified); Intent.putextra ("Crop", "true");//Aspectx aspecty is a proportional Intent.putextra ("Aspectx", 1); Intent.putextra ("Aspecty", 1) ;//Outputx outputy is a cropped image with a wide height of Intent.putextra ("Outputx", 300); Determines the pixel Intent.putextra of the picture ("Outputy", 300);        Determines the pixel Intent.putextra of the picture ("Return-data", true); Activity.startactivityforresult (Intent, photoresult);} /** * albums | | Photographic results return processing in the activity's Onactivityresult * @param activity * @param requestcode * @param resultcode * @param data * @return */public Static object[] Handleresultfromcameraorphotos (activity activity, int requestcode, int resultcode, Intent data)          {if (ResultCode = = NONE) return null; Photo if (Requestcode = = Photohraph) {AppContext ApplicationContext = (AppContext) activity.getapplicationcontext ();        String name= "temp";//+applicationcontext.setnum (); name= "Temp";        String path = environment.getexternalstoragedirectory () + "/" +name+ ". jpg";            SYSTEM.OUT.PRINTLN (path);            File picture = new file (path);            Photouri = Data.getdata ();          Startphotozoom (Activity,photouri);                    } if (data = = NULL) return null;            Read album zoom picture if (Requestcode = = photozoom) {Photouri = Data.getdata ();          Startphotozoom (Activity,data.getdata ());              }//Processing result if (Requestcode = = photoresult) {Bundle extras = Data.getextras ();            if (extras! = null) {//photouri = Data.getdata ();              String picpath = null;                    String[] Pojo = {MediaStore.Images.Media.DATA}; cursor cursor = activity.managedquery (Photouri, Pojo, NULL, null,nULL); if (cursor! = NULL) {int columnindex = Cursor.getcolumnindexo                        Rthrow (Pojo[0]);                        Cursor.movetofirst ();                        Picpath = cursor.getstring (columnindex);                    Cursor.close ();            } log.d ("TAG", Picpath + "");                  Bitmap photo = extras.getparcelable ("Data");                  Bytearrayoutputstream stream = new Bytearrayoutputstream (); Photo.compress (Bitmap.CompressFormat.JPEG, +, stream);//(0-100) compressed file object[] HashMap = new Object[2]                ;                Hashmap[1] = photo;                Hashmap[0] = Picpath;                Photo.recycle ();             return HASHMAP;     }}return null;}

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.