- <span style="font-size:18px;">我们在做一些东西的时候会必不可少的调用系统自带设备功能,比如一些视频,拍照一类所以这里总结了一些常见的功能通过Intent 调用的用法!</span>
- //选择图片 requestCode 返回的标识
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT); //"android.intent.action.GET_CONTENT"
- intent.setType(contentType); //查看类型 String IMAGE_UNSPECIFIED = "image/*";
- Intent wrapperIntent = Intent.createChooser(intent, null);
- ((Activity) context).startActivityForResult(wrapperIntent, requestCode);
- //添加音频
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
- Intent wrapperIntent = Intent.createChooser(intent, null);
- ((Activity) context).startActivityForResult(wrapperIntent, 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);
- //视频
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
- intent.setType(contentType); //String VIDEO_UNSPECIFIED = "video/*";
- Intent wrapperIntent = Intent.createChooser(intent, 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);
- //拍照 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);