1, add the following code in the Androidmanifest.xml
<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
<uses-permission android:name= "Android.permission.INTERNET"/>
<uses-permission android:name= "Android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"
Tools:ignore= "Protectedpermissions"/>
<application
<provider
Android:authorities= "${applicationid}.provider"
Android:name= "Android.support.v4.content.FileProvider"
Android:exported= "false"
Android:granturipermissions= "true" >
<meta-data android:name= "Android.support.FILE_PROVIDER_PATHS"
Android:resource= "@xml/provider_paths" >
</meta-data>
</provider>
</application></manifest>
2. Create a new XML folder in the Res directory and create a new provider_paths XML file
<?xml version= "1.0" encoding= "Utf-8"? ><paths xmlns:android= "Http://schemas.android.com/apk/res/android" > <external-path name= "External_files" path= "." /></paths>
3. Open the camera in the main file
Intent intent=new Intent (mediastore.action_video_capture);
try {
Fileuri=uri.fromfile (Createmediafile ()); If this is the case, it will be an error
Fileuri= Fileprovider.geturiforfile (Cameravideoactivity.this,getapplicationcontext (). GetPackageName () + ". Provider ", Createmediafile ());//This is the correct wording
} catch (IOException e) {
E.printstacktrace ();
}
Intent.putextra (Mediastore.extra_output,fileuri);
Intent.putextra (mediastore.extra_video_quality,1);
Startactivityforresult (intent,1);
4. How to create and save videos
Private File Createmediafile () throws IOException {
if (utils.checksdcardavaliable ()) {
if ((Environment.getexternalstoragestate (). Equals (environment.media_mounted))) {
Select your Own folder
String path = Environment.getexternalstoragedirectory (). GetPath () + "/myvideo/";
Constants.video_url is a constant that represents the folder where the video is stored
File Mediastoragedir = new file (path);
if (!mediastoragedir.exists ()) {
if (!mediastoragedir.mkdirs ()) {
LOG.E ("TAG", "Folder creation failed");
return null;
}
}
The file is named according to the current number of milliseconds
String TimeStamp = string.valueof (System.currenttimemillis ());
TimeStamp = timestamp.substring (7);
String imagefilename = "V" + timeStamp;
String suffix = ". mp4";
File MediaFile = new file (Mediastoragedir + file.separator + imagefilename + suffix);
return mediafile;
}
}
return null;
}
}
5. Overriding the Onactivityresult method
@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
if (requestcode==1)
{
if (RESULTCODE==RESULT_OK)
{
Toast.maketext (This, "Video saved to:\n" +
Data.getdata (), Toast.length_long). Show ();
Vv_play.setvideouri (Fileuri);
Vv_play.requestfocus ();
}
}
}
6, DDMS
Android calls system camera to record and save