Android camera Feature

Source: Internet
Author: User

This evening starting from 22 o'clock has been over there to test the photo flashback situation, really tangled! Then another project was built to re-test, found that the new project has not been the case of the flash back. So I started uninstalling the project and found that there was no flash back after the reinstallation. After uploading about 3-4 photos, we started to flash back. So finally find out the root cause of the flash is not enough memory!

Finally Kung Fu is not a conscientious, and found the problem lies. Still find the problem is the most important, put the code below.

First, upload some core class libraries to get a root path.

 Public class uploadimage {    //  get the SD card root directory address and create the image parent directory file object and file object;    Private Static String file_str = environment.getexternalstoragedirectory (). GetPath ();      Public Static New File (file_str + "/rzproject");}


If a button has been clicked, a selection box pops up first.

/*** Select photos! */Private voidSetphotos () {NewAlertdialog.builder (mainactivity. This). Settitle ("Hint"). Setmessage ("Please choose how to get Pictures"). Setnegativebutton ("Cancel",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface arg0,intarg1)                {Arg0.cancel (); }}). Setpositivebutton ("Take pictures",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intID) {Takephotos (); }}). Setneutralbutton ("Albums",NewDialoginterface.onclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)                {Selectphotos (); }}). Show ();}

That format is really uncoordinated! Forget it, stick to the code!

PrivateString Fileimagename;Private Static Final intPhoto_graph = 1;Private Static Final intPhoto_select = 2;Private voidTakephotos () {//Verify that the SD card is properly installed:    if(Environment.MEDIA_MOUNTED.equals (Environment. Getexternalstoragestate ())) {//The parent directory is created first, and if the parent directory does not exist when a new file is created, the parent directory must be created before creating a new file.         if(!UploadImage.mars_file.exists ())        {UploadImage.mars_file.mkdirs (); } Intent Intent=NewIntent (mediastore.action_image_capture); Fileimagename= Uploadimage.mars_file + "/" +Viewutil.getnewguid ()+ ". jpg"; File Newfile_go=NewFile (fileimagename);        Intent.putextra (Mediastore.extra_output, Uri.fromfile (Newfile_go)); //jump to the photo screen;Startactivityforresult (Intent, photo_graph); } Else {        //viewutil.showtoast ("SD card not Found", false);    }}/*** Choose from albums **/Private voidSelectphotos () {Intent Intent=NewIntent (intent.action_get_content); Intent.settype ("Image/*"); Startactivityforresult (Intent, Photo_select);}

Next is the callback function after selecting the image.

@Overrideprotected voidOnactivityresult (intRequestcode,intResultCode, Intent data) {    Super. Onactivityresult (Requestcode, ResultCode, data); if(Requestcode = = Photo_graph && ResultCode = =RESULT_OK)        {Showprogressdialog (r.string.phots_string); NewImagethread (Fileimagename). Start (); } Else if(Requestcode = = Photo_select && ResultCode = =RESULT_OK) {String path=Viewutil.getphotospath (data);    Copyphotos (path); }   }

There should still be a way to take pictures, which has not been studied for the time being. Temporarily skipped!

Android camera Feature

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.