通过调用本地自带的拍照和录视频功能、比较简单、因为都是平时写的工具类代码、方便直接调用、就直接上代码了、
调用拍照功能、
/**
* 拍照
* @param activity
* @param requestCode
* @param fileFullPath
*
*/
public static void imageCapture(Activity activity,int requestCode,String fileFullPath){
if(StringUtils.getString(fileFullPath)==null){
return;
}
String path = fileFullPath.substring(0, fileFullPath.lastIndexOf('/')+1);
String fileName = fileFullPath.substring(fileFullPath.lastIndexOf('/')+1);
imageCapture(activity, requestCode, path, fileName);
}
public static void imageCapture(Activity activity,int requestCode,String path,String fileName){
LogUtils.logI("路径:"+path+"文件名:"+fileName);
if(path.indexOf('/')==-1){
path+='/';
}
File dirFile = new File(path);
if(!dirFile.exists()){
FileUtils.createNewDir(path);
LogUtils.logI("创建路径:"+path);
}
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(path+fileName);
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(intent,requestCode);
}
调用录视频功能、
/**
* 录视频
* @param activity
* @param requestCode
* @param fileFullPath
*
*/
public static void videoCapture(Activity activity,int requestCode,String fileFullPath){
if(StringUtils.getString(fileFullPath)==null){
return;
}
String path = fileFullPath.substring(0, fileFullPath.lastIndexOf('/')+1);
String fileName = fileFullPath.substring(fileFullPath.lastIndexOf('/')+1);
videoCapture(activity, requestCode, path, fileName);
}
public static void videoCapture(Activity activity,int requestCode,String path,String fileName){
if(path.indexOf('/')==-1){
path+='/';
}
File dirFile = new File(path);
if(!dirFile.exists()){
FileUtils.createNewDir(path);
}
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
File file = new File(path+fileName);
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
activity.startActivityForResult(intent,requestCode);
}
所需要的权限、
<uses-permission android:name="android.permission.CAMERA" />
如果想要得到拍照或拍视频后 的文件、可以覆写Activity里面的onActivityResult方法来得到你想要的文件、