---restore content starts---
1, take pictures, here directly on the code, see the comments on the good
Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); Takephoto=(Button) Findviewbyid (R.id.take_photo); Photo=(ImageView) Findviewbyid (R.id.photo); Takephoto.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (view view) {File Outputimage=NewFile (Environment.getexternalstoragedirectory (), "tempimage.jpg");//a new file class is created here, which is used to save the picture taken, getExternalStorageDirectory (), which indicates that there is a mobile SD card root directory Try{ if(Outputimage.exists ()) {outputimage.delete (); } outputimage.createnewfile (); }Catch(IOException e) {e.printstacktrace (); } Imageuri= Uri.fromfile (outputimage);//convert a file to a URI objectIntent Intent =NewIntent ("Android.media.action.IMAGE_CAPTURE");//action to start the camera programIntent.putextra (Mediastore.extra_output, Imageuri);//specifies that the image output address is the URI object created before the photo is takenStartactivityforresult (Intent, Take_photo);//Start the camera } });}
--File storage required by permissions:
<android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
2. Photo Album Select photos and show:
Choosephoto = (Button) Findviewbyid (R.id.choose_photo); Choosephoto.setonclicklistener (new View.onclicklistener () { @Override publicvoid OnClick (view view) { New Intent (Intent.action_pick,android.provider.mediastore.images.media.external_content_uri); // opens the album and returns the URI of the selected photo Startactivityforresult (Intent, Choose_photo); });
protected voidOnactivityresult (intRequestcode,intResultCode, Intent data) { Super. Onactivityresult (Requestcode, ResultCode, data); Switch(requestcode) { CaseChoose_photo:if(ResultCode = =RESULT_OK) { Try{URI Uri= Data.getdata ();//gets the URI of the selected pictureBitmap Bitmap = Bitmapfactory.decodestream (Getcontentresolver (). Openinputstream (URI));//load picture as bitmap according to URIPhoto.setimagebitmap (bitmap); }Catch(FileNotFoundException e) {e.printstacktrace (); } } Break; }}
--The above operation, because the selected picture may be very large, usually need to compress and then display;
3. Audio playback
1) using the MediaPlayer class to achieve audio playback in Android, its common control methods are:
--setdatasource (): Sets the location of the audio file to play;
--prepare (): Call this method to complete the preparation before starting playback;
--start (): Start or continue playing audio;
--pause (): pauses audio playback;
--reset (): Resets the MediaPlayer object to the state you just created;
--seekto (): Starts playing audio from the specified position;
--stop (): Stops playing audio. The MediaPlayer object after calling this method can no longer play audio
--release (): Release the resources associated with the MediaPlayer object;
--isplaying (): Determines whether the current MediaPlayer is playing audio;
--getduration (): Gets the length of the loaded audio file;
4. Play Video:
1) using the Videoview class to achieve video operation in Android, its common methods are:
--setvideopath (): Sets the location of the video file to be played;
--start (): Start or continue playing the video;
--pause (): Pause video playback;
--resume (): Start the video playback;
--seekto (): Starts playing the video from the specified position;
--isplaying (): Determines whether the video is currently playing;
--getduration (): Gets the length of the loaded video file;
--suspend (): Release video resources;
android--Multimedia Operations