WEB开发网
开发学院手机开发Android 开发 Android拍照、录像、录音代码范例 阅读

Android拍照、录像、录音代码范例

 2010-07-15 20:54:00 来源:WEB开发网   
核心提示:super.onCreate(savedInstanceState);this.setContentView(R.layout.problem_report);}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Inten

super.onCreate(savedInstanceState);

this.setContentView(R.layout.problem_report);

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {

case RESULT_CAPTURE_IMAGE://拍照

if (resultCode == RESULT_OK) {

Toast.makeText(this, strImgPath, Toast.LENGTH_SHORT).show();

}

break;

case REQUEST_CODE_TAKE_VIDEO://拍摄视频

if (resultCode == RESULT_OK) {

Uri uriVideo = data.getData();

Cursor cursor=this.getContentResolver().query(uriVideo, null, null, null, null);

if (cursor.moveToNext()) {

/* _data:文件的绝对路径 ,_display_name:文件名 */

strVideoPath = cursor.getString(cursor.getColumnIndex("_data"));

Toast.makeText(this, strVideoPath, Toast.LENGTH_SHORT).show();

}

}

break;

case RESULT_CAPTURE_RECORDER_SOUND://录音

if (resultCode == RESULT_OK) {

Uri uriRecorder = data.getData();

Cursor cursor=this.getContentResolver().query(uriRecorder, null, null, null, null);

if (cursor.moveToNext()) {

/* _data:文件的绝对路径 ,_display_name:文件名 */

strRecorderPath = cursor.getString(cursor.getColumnIndex("_data"));

Toast.makeText(this, strRecorderPath, Toast.LENGTH_SHORT).show();

}

}

break;

}

}

/**

* 照相功能

*/

private void cameraMethod() {

Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

strImgPath = Environment.getExternalStorageDirectory().toString() + "/CONSDCGMPIC/";//存放照片的文件夹

String fileName = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())

Tags:Android 拍照 录像

编辑录入:coldstar [复制链接] [打 印]
赞助商链接