packagecom.cons.dcg.collect; |
004 | importjava.text.SimpleDateFormat; |
007 | importandroid.content.Intent; |
008 | importandroid.database.Cursor; |
009 | importandroid.net.Uri; |
010 | importandroid.os.AsyncTask; |
011 | importandroid.os.Bundle; |
012 | importandroid.os.Environment; |
013 | importandroid.provider.MediaStore; |
014 | importandroid.view.*; |
015 | importandroid.widget.*; |
017 | publicclassRecordActivityextendsActivityimplementsOnClickListener { |
019 | privatestaticfinalintRESULT_CAPTURE_IMAGE =1;// 照相的requestCode |
020 | privatestaticfinalintREQUEST_CODE_TAKE_VIDEO =2;// 摄像的照相的requestCode |
021 | privatestaticfinalintRESULT_CAPTURE_RECORDER_SOUND =3;// 录音的requestCode |
023 | privateString strImgPath ="";// 照片文件绝对路径 |
024 | privateString strVideoPath ="";// 视频文件的绝对路径 |
025 | privateString strRecorderPath ="";// 录音文件的绝对路径 |
028 | protectedvoidonCreate(Bundle savedInstanceState) { |
029 | super.onCreate(savedInstanceState); |
030 | this.setContentView(R.layout.problem_report); |
034 | protectedvoidonActivityResult(intrequestCode,intresultCode, Intent data) { |
035 | super.onActivityResult(requestCode, resultCode, data); |
036 | switch(requestCode) { |
037 | caseRESULT_CAPTURE_IMAGE://拍照 |
038 | if(resultCode == RESULT_OK) { |
039 | Toast.makeText(this, strImgPath, Toast.LENGTH_SHORT).show(); |
042 | caseREQUEST_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 | caseRESULT_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 | privatevoidcameraMethod() { |
073 | Intent imageCaptureIntent =newIntent(MediaStore.ACTION_IMAGE_CAPTURE); |
074 | strImgPath = Environment.getExternalStorageDirectory().toString() +"/CONSDCGMPIC/";//存放照片的文件夹 |
075 | String fileName =newSimpleDateFormat("yyyyMMddHHmmss").format(newDate()) +".jpg";//照片命名 |
076 | File out =newFile(strImgPath); |
080 | out =newFile(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 | privatevoidvideoMethod() { |
093 | Intent intent =newIntent(MediaStore.ACTION_VIDEO_CAPTURE); |
094 | intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,0); |
095 | startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO); |
101 | privatevoidsoundRecorderMethod() { |
102 | Intent intent =newIntent(Intent.ACTION_GET_CONTENT); |
103 | intent.setType("audio/amr"); |
104 | startActivityForResult(intent, RESULT_CAPTURE_RECORDER_SOUND); |
112 | privatevoidshowToast(String text,intduration) { |
113 | Toast.makeText(ProblemReport.this, text, duration).show(); |
转载于:https://my.oschina.net/u/573470/blog/135695