Android implementation of photo, video, audio code example _android

Source: Internet
Author: User

This article mainly introduces the android to achieve photo, video, recording code data, here sorted out the detailed code, the need for small partners can refer to.

Recordactivity.java

Package com.cons.dcg.collect;
Import Java.io.File;
Import Java.text.SimpleDateFormat;
Import java.util.*;
Import android.app.*;
Import android.content.Intent;
Import Android.database.Cursor;
Import Android.net.Uri;
Import Android.os.AsyncTask;
Import Android.os.Bundle;
Import android.os.Environment;
Import Android.provider.MediaStore;
Import android.view.*;
Import android.widget.*; public class Recordactivity extends activity implements Onclicklistener {private static final int Result_capture_imag E = 1;//Photo Requestcode private static final int request_code_take_video = 2;//camera photography Requestcode private static F inal int result_capture_recorder_sound = 3;//recording Requestcode private String Strimgpath = "";//Photo file absolute path private St Ring Strvideopath = ""//Video file absolute path private String Strrecorderpath = "";//audio file absolute path @Override protected voi
        D onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); This.setcontentview (r.layout.problEm_report); @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivi
        Tyresult (Requestcode, ResultCode, data); Switch (requestcode) {case result_capture_image://photo if (ResultCode = = RESULT_OK) {T
            Oast.maketext (This, Strimgpath, Toast.length_short). Show ();
        } break; Case request_code_take_video://Shooting Video if (ResultCode = = RESULT_OK) {Uri Urivideo = Data.getdata
                ();
                Cursor cursor=this.getcontentresolver (). query (urivideo, NULL, NULL, NULL, NULL); if (Cursor.movetonext ()) {/** _data: Absolute path of file, _display_name: file name/Strvideopath =
                    Cursor.getstring (Cursor.getcolumnindex ("_data"));
                Toast.maketext (This, Strvideopath, Toast.length_short). Show ();
        }} break;
        Case result_capture_recorder_sound://Recording    if (ResultCode = = RESULT_OK) {Uri Urirecorder = Data.getdata ();
                Cursor cursor=this.getcontentresolver (). query (urirecorder, NULL, NULL, NULL, NULL);  if (Cursor.movetonext ()) {/** _data: Absolute path of file, _display_name: file name/Strrecorderpath
                    = Cursor.getstring (Cursor.getcolumnindex ("_data"));
                Toast.maketext (This, Strrecorderpath, Toast.length_short). Show ();
        }} break; }/** * Camera function/private void Cameramethod () {Intent imagecaptureintent = new Intent (Media
        Store.action_image_capture); Strimgpath = Environment.getexternalstoragedirectory (). toString () + "/consdcgmpic/";//the folder where the photos are stored String fileName = n
        EW SimpleDateFormat ("YYYYMMDDHHMMSS"). Format (new Date ()) + ". jpg";//photo name file out = new file (Strimgpath);
        if (!out.exists ()) {out.mkdirs (); } out = newFile (Strimgpath, fileName);
        Strimgpath = Strimgpath + filename;//The image's absolute path uri uri = Uri.fromfile (out);
        Imagecaptureintent.putextra (Mediastore.extra_output, URI);
        Imagecaptureintent.putextra (mediastore.extra_video_quality, 1);
 
    Startactivityforresult (Imagecaptureintent, result_capture_image); /** * Shooting video/private void Videomethod () {Intent Intent = new Intent (mediastore.action_video_
        CAPTURE);
        Intent.putextra (mediastore.extra_video_quality, 0);
    Startactivityforresult (Intent, request_code_take_video); /** * Recording function/private void Soundrecordermethod () {Intent Intent = new Intent (intent.action_ge
        T_content);
        Intent.settype ("Audio/amr");
    Startactivityforresult (Intent, result_capture_recorder_sound); /** * Hint Info * @param text * @param duration/private void Showtoast (String text, int dura tion) {Toast.maketext (PrOblemreport.this, text, duration). Show ();
 }
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

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.