This article mainly introduces the information on Android's photo, video and audio recording codes. The detailed code has been sorted out here. Friends who need it can refer to it.
package ; import ; import ; import .*; import .*; import ; import ; import ; import ; import ; import ; import ; import .*; import .*; public class RecordActivity extends Activity implements OnClickListener { private static final int RESULT_CAPTURE_IMAGE = 1;// Photo requestCode private static final int REQUEST_CODE_TAKE_VIDEO = 2;// RequestCode for photography private static final int RESULT_CAPTURE_RECORDER_SOUND = 3;//Record requestCode private String strImgPath = "";// Absolute path to the photo file private String strVideoPath = "";// Absolute path to video file private String strRecorderPath = "";// Absolute path to recording file @Override protected void onCreate(Bundle savedInstanceState) { (savedInstanceState); (.problem_report); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { (requestCode, resultCode, data); switch (requestCode) { case RESULT_CAPTURE_IMAGE://Photograph if (resultCode == RESULT_OK) { (this, strImgPath, Toast.LENGTH_SHORT).show(); } break; case REQUEST_CODE_TAKE_VIDEO://Shoot the video if (resultCode == RESULT_OK) { Uri uriVideo = (); Cursor cursor=().query(uriVideo, null, null, null, null); if (()) { /** _data: the absolute path of the file, _display_name: the file name */ strVideoPath = (("_data")); (this, strVideoPath, Toast.LENGTH_SHORT).show(); } } break; case RESULT_CAPTURE_RECORDER_SOUND://recording if (resultCode == RESULT_OK) { Uri uriRecorder = (); Cursor cursor=().query(uriRecorder, null, null, null, null); if (()) { /** _data: the absolute path of the file, _display_name: the file name */ strRecorderPath = (("_data")); (this, strRecorderPath, Toast.LENGTH_SHORT).show(); } } break; } } /** * Photo function */ private void cameraMethod() { Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); strImgPath = ().toString() + "/CONSDCGMPIC/";//The folder where you store photos String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg";//Photo name File out = new File(strImgPath); if (!()) { (); } out = new File(strImgPath, fileName); strImgPath = strImgPath + fileName;//The absolute path to this photo Uri uri = (out); (MediaStore.EXTRA_OUTPUT, uri); (MediaStore.EXTRA_VIDEO_QUALITY, 1); startActivityForResult(imageCaptureIntent, RESULT_CAPTURE_IMAGE); } /** * Shooting video */ private void videoMethod() { Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); (MediaStore.EXTRA_VIDEO_QUALITY, 0); startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO); } /** * Recording function */ private void soundRecorderMethod() { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); ("audio/amr"); startActivityForResult(intent, RESULT_CAPTURE_RECORDER_SOUND); } /** * Prompt message * @param text * @param duration */ private void showToast(String text, int duration) { (, text, duration).show(); } }
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.