引用http://www.oschina.net/code/snippet_163910_6069
[文件] RecordActivity.java ~ 5KB 下载(12)
001 |
package com.cons.dcg.collect; |
004 |
import java.text.SimpleDateFormat; |
006 |
import android.app.*; |
007 |
import android.content.Intent; |
008 |
import android.database.Cursor; |
009 |
import android.net.Uri; |
010 |
import android.os.AsyncTask; |
011 |
import android.os.Bundle; |
012 |
import android.os.Environment; |
013 |
import android.provider.MediaStore; |
014 |
import android.view.*; |
015 |
import android.widget.*; |
017 |
public class RecordActivity extends Activity implements OnClickListener { |
019 |
private static final int RESULT_CAPTURE_IMAGE = 1 ; |
020 |
private static final int REQUEST_CODE_TAKE_VIDEO = 2 ; |
021 |
private static final int RESULT_CAPTURE_RECORDER_SOUND = 3 ; |
023 |
private String strImgPath = "" ; |
024 |
private String strVideoPath = "" ; |
025 |
private String strRecorderPath = "" ; |
028 |
protected void onCreate(Bundle savedInstanceState) { |
029 |
super .onCreate(savedInstanceState); |
030 |
this .setContentView(R.layout.problem_report); |
034 |
protected void onActivityResult( int requestCode, int resultCode, Intent data) { |
035 |
super .onActivityResult(requestCode, resultCode, data); |
036 |
switch (requestCode) { |
037 |
case RESULT_CAPTURE_IMAGE: |
038 |
if (resultCode == RESULT_OK) { |
039 |
Toast.makeText( this , strImgPath, Toast.LENGTH_SHORT).show(); |
042 |
case REQUEST_CODE_TAKE_VIDEO: |
043 |
if (resultCode == RESULT_OK) { |
044 |
Uri uriVideo = data.getData(); |
045 |
Cursor cursor= this .getContentResolver().query(uriVideo, null , null , null , null ); |
046 |
if (cursor.moveToNext()) { |
047 |
/** _data:文件的绝对路径 ,_display_name:文件名 */ |
048 |
strVideoPath = cursor.getString(cursor.getColumnIndex( "_data" )); |
049 |
Toast.makeText( this , strVideoPath, Toast.LENGTH_SHORT).show(); |
053 |
case RESULT_CAPTURE_RECORDER_SOUND: |
054 |
if (resultCode == RESULT_OK) { |
055 |
Uri uriRecorder = data.getData(); |
056 |
Cursor cursor= this .getContentResolver().query(uriRecorder, null , null , null , null ); |
057 |
if (cursor.moveToNext()) { |
058 |
/** _data:文件的绝对路径 ,_display_name:文件名 */ |
059 |
strRecorderPath = cursor.getString(cursor.getColumnIndex( "_data" )); |
060 |
Toast.makeText( this , strRecorderPath, Toast.LENGTH_SHORT).show(); |
072 |
private void cameraMethod() { |
073 |
Intent imageCaptureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); |
074 |
strImgPath = Environment.getExternalStorageDirectory().toString() + "/CONSDCGMPIC/" ; |
075 |
String fileName = new SimpleDateFormat( "yyyyMMddHHmmss" ).format( new Date()) + ".jpg" ; |
076 |
File out = new File(strImgPath); |
080 |
out = new File(strImgPath, fileName); |
081 |
strImgPath = strImgPath + fileName; |
082 |
Uri uri = Uri.fromFile(out); |
083 |
imageCaptureIntent.putExtra(MediaStore.EXTRA_OUTPUT, uri); |
084 |
imageCaptureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1 ); |
085 |
startActivityForResult(imageCaptureIntent, RESULT_CAPTURE_IMAGE); |
092 |
private void videoMethod() { |
093 |
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); |
094 |
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0 ); |
095 |
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO); |
101 |
private void soundRecorderMethod() { |
102 |
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
103 |
intent.setType( "audio/amr" ); |
104 |
startActivityForResult(intent, RESULT_CAPTURE_RECORDER_SOUND); |
112 |
private void showToast(String text, int duration) { |
113 |
Toast.makeText(ProblemReport. this , text, duration).show(); |