本文實例講述了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);更多關于Android相關內容感興趣的讀者可查看本站專題:《Android多媒體操作技巧匯總(音頻,視頻,錄音等)》、《Android開發入門與進階教程》、《Android視圖View技巧總結》、《Android編程之activity操作技巧總結》、《Android操作SQLite數據庫技巧總結》、《Android操作json格式數據技巧總結》、《Android數據庫操作技巧總結》、《Android文件操作技巧匯總》、《Android編程開發之SD卡操作方法匯總》、《Android資源操作技巧匯總》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
新聞熱點
疑難解答