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 );
}