技術博文2016/08/31

【APP開發】Android中拍照、圖片、錄音、視訊和音訊功能的方法和程式碼

Android中拍照、圖片、錄音、視訊和音訊功能的方法和程式碼
 
//選擇圖片 requestCode 返回的標識
Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT); //”android.intent.action.GET_CONTENT”
innerIntent.setType(contentType); //檢視型別 String IMAGE_UNSPECIFIED = “image/*”;
Intent wrapperIntent = Intent.createChooser(innerIntent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
 
//視訊
Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = “video/*”;
Intent wrapperIntent = Intent.createChooser(innerIntent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
 
//新增音訊
Intent innerIntent = new Intent(Intent.ACTION_GET_CONTENT);
innerIntent.setType(contentType); //String VIDEO_UNSPECIFIED = “video/*”;
Intent wrapperIntent = Intent.createChooser(innerIntent, null);
((Activity) context).startActivityForResult(wrapperIntent, requestCode);
 
//錄音
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType(ContentType.AUDIO_AMR); //String AUDIO_AMR = “audio/amr”;
intent.setClassName(“com.android.soundrecorder”,
“com.android.soundrecorder.SoundRecorder”);
((Activity) context).startActivityForResult(intent, requestCode);
 
//拍攝視訊
int durationLimit = getVideoCaptureDurationLimit(); //SystemProperties.getInt(“ro.media.enc.lprof.duration”, 60);
Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
intent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, sizeLimit);
intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationLimit);
startActivityForResult(intent, REQUEST_CODE_TAKE_VIDEO);
 
//拍照 REQUEST_CODE_TAKE_PICTURE 為返回的標識
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //”android.media.action.IMAGE_CAPTURE”;
intent.putExtra(MediaStore.EXTRA_OUTPUT, Mms.ScrapSpace.CONTENT_URI); // output,Uri.parse(“content://mms/scrapSpace”);
startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE);

本文來自新浪部落格