Android-simple camera program

Source: Internet
Author: User

This article translated from: http://developer.android.com/training/camera/videobasics.html

This article describes how to use the existing Camera application to take videos.

If your application only needs to integrate a small part of the video function, you can use the camera application provided on most Android devices to take videos.

Apply for camera Permissions

Put a <uses-feature> label in the configuration file to apply for camera dependency for your application:

<Manifest...
>
<Uses-feature Android: Name = "android. Hardware. Camera"/>
...
</Manifest...>

If your application is not required for camera usage, add the Android: required = "false" attribute to the tag. In this way, Google
Play will allow devices without cameras to download your applications. Then, your application will be responsible for checking whether there are available cameras on the device it is running on. You can call the hassystemfeature (packagemanager. feature_camera) method to complete the function check. If no camera is available, disable the camera function.

Video shooting using the camera Application

Android uses an itent object that describes your intent and delegates related operations to other applications. This call is completed in three sections: 1. Create an intent object; 2. Call the external activity to be started; 3. process the video code when the Focus returns your activity.

The following function calls an intent to take a video:

Privatevoiddispatchtakevideointent (){
Intent takevideointent = new intent (mediastore. action_video_capture );
Startactivityforresult (takevideointent, action_take_video );
}

The best practice is to ensure that an application can process your intent object before calling this method. The following is a function that can check whether there are applications that process your intent object:

Publicstaticbooleanisintentavailable (Context
Context, string action ){
Final packagemanagerpackagemanager = context. getpackagemanager ();
Final intent = new intent (action );
List <resolveinfo> List =
Packagemanager. queryintentactivities (intent,
Packagemanager. match_default_only );
Return list. Size ()> 0;
}

View videos

The android camera application carries a URI pointing to the video storage location in the intent parameter of the onactivityresult () callback method returned to the caller. The following is the code for receiving a video and displaying it in videoview:

Privatevoidhandlecameravideo (intent
Intent ){
Mvideouri = intent. getdata ();
Mvideoview. setvideouri (mvideouri );
}

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.