由於專案需要,簡單開發一個app,整合了拍照、錄音、錄影功能,資料暫時儲存在本地,部分程式碼展示如下。
private void cameraMethod() {
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
strImgPath = Environment.getExternalStorageDirectory().toString() + "/CONSDCGMPIC/";//存放照片的資料夾
String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + ".jpg";//照片命名
File out = new File(strImgPath);
if (!out.exists()) {
out.mkdirs();
}
out = new File(strImgPath, fileName);
strImgPath = strImgPath + fileName;//該照片的絕對路徑
Uri uri = Uri.fromFile(out);
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
startActivityForResult(imageCaptureIntent, RESULT_CAPTURE_IMAGE);
}
private void soundRecorderMethod()
{
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("audio/amr");
startActivityForResult(intent, RESULT_CAPTURE_RECORDER_SOUND);
}
private void videoMethod()
{
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
}
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
頁面佈局設計:(程式碼太長,直接上圖)
後續考慮將收集到的資訊上傳到雲端,正在努力;工程檔案程式碼