Java Code Examples for android.provider.MediaStore#ACTION_VIDEO_CAPTURE

The following examples show how to use android.provider.MediaStore#ACTION_VIDEO_CAPTURE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CameraCompat.java    From YImagePicker with Apache License 2.0 8 votes vote down vote up
private static Intent getTakeVideoIntent(Activity activity, Uri imageUri, long maxDuration) {
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        if (Build.VERSION.SDK_INT < 21) {
            List<ResolveInfo> resInfoList = activity.getPackageManager()
                    .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
            for (ResolveInfo resolveInfo : resInfoList) {
                String packageName = resolveInfo.activityInfo.packageName;
                activity.grantUriPermission(packageName, imageUri,
                        Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
            }
        }
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        if (maxDuration > 1) {
            intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, maxDuration / 1000L);
        }
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
    }
    return intent;
}
 
Example 2
Source File: SelectPictureActivity.java    From SiliCompressor with Apache License 2.0 7 votes vote down vote up
private void dispatchTakeVideoIntent() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    takeVideoIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        try {

            takeVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, 10);
            takeVideoIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            capturedUri = FileProvider.getUriForFile(this,
                    getPackageName() + FILE_PROVIDER_AUTHORITY,
                    createMediaFile(TYPE_VIDEO));

            takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedUri);
            Log.d(LOG_TAG, "VideoUri: " + capturedUri.toString());
            startActivityForResult(takeVideoIntent, REQUEST_TAKE_VIDEO);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
 
Example 3
Source File: CustomWebViewModule.java    From react-native-webview-android-file-upload with MIT License 6 votes vote down vote up
private Uri getOutputFilename(String intentType) {
    String prefix = "";
    String suffix = "";

    if (intentType == MediaStore.ACTION_IMAGE_CAPTURE) {
        prefix = "image-";
        suffix = ".jpg";
    } else if (intentType == MediaStore.ACTION_VIDEO_CAPTURE) {
        prefix = "video-";
        suffix = ".mp4";
    }

    String packageName = getReactApplicationContext().getPackageName();
    File capturedFile = null;
    try {
        capturedFile = createCapturedFile(prefix, suffix);
    } catch (IOException e) {
        Log.e("CREATE FILE", "Error occurred while creating the File", e);
        e.printStackTrace();
    }
    return FileProvider.getUriForFile(getReactApplicationContext(), packageName+".fileprovider", capturedFile);
}
 
Example 4
Source File: MediaPickerFragment.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
public void requestVideo() {
    this.pickCropped = false;

    //
    // Generating Temporary File Name
    //
    pendingFile = generateRandomFile(".mp4");
    if (pendingFile == null) {
        return;
    }


    //
    // Requesting Video
    //
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(pendingFile)));
    startActivityForResult(intent, REQUEST_VIDEO);
}
 
Example 5
Source File: MainActivity.java    From lbry-android with MIT License 6 votes vote down vote up
public void requestVideoCapture() {
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (intent.resolveActivity(getPackageManager()) != null) {
        String outputPath = String.format("%s/record", Utils.getAppInternalStorageDir(this));
        File dir = new File(outputPath);
        if (!dir.isDirectory()) {
            dir.mkdirs();
        }

        cameraOutputFilename = String.format("%s/VID_%s.mp4", outputPath, Helper.FILESTAMP_FORMAT.format(new Date()));
        Uri outputUri = FileProvider.getUriForFile(this, String.format("%s.fileprovider", getPackageName()), new File(cameraOutputFilename));
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputUri);
        startActivityForResult(intent, REQUEST_VIDEO_CAPTURE);
        return;
    }

    showError(getString(R.string.cannot_capture_video));
}
 
Example 6
Source File: VideoListActivity.java    From mobilecloud-15 with Apache License 2.0 5 votes vote down vote up
/**
 * Displays a chooser dialog that gives options
 * to upload video from either by Gallery or by 
 * VideoRecorder.
 */
private void displayChooserDialog() {
    // Create an intent that will start an Activity to
    // get Video from Gallery.
    final Intent videoGalleryIntent =
        new Intent(Intent.ACTION_GET_CONTENT)
              .setType("video/*")
              .putExtra(Intent.EXTRA_LOCAL_ONLY, true);
    
    // Create an intent that will start an Activity to
    // Record the Video.
    final Intent recordVideoIntent =
        new Intent(MediaStore.ACTION_VIDEO_CAPTURE);

    // Intent that wraps the given target Intent and
    // shows a chooser dialog to show the Apps that 
    // can handle the target Intent.
    final Intent chooserIntent =
        Intent.createChooser(videoGalleryIntent, "Upload Video via");

    // Add RecordVideo Intent, so that App that can
    // record video is added to the chooser dialog.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                           new Intent[] { recordVideoIntent });
    
    // Starts an Activity to get the Video either by Gallery
    // or by VideoRecorder.
    startActivityForResult(chooserIntent, REQUEST_GET_VIDEO);

}
 
Example 7
Source File: MediaUtils.java    From android-utils with MIT License 5 votes vote down vote up
/**
 * Creates an intent to take a video from camera or gallery or any other application that can
 * handle the intent.
 *
 * @param ctx
 * @param savingUri
 * @param durationInSeconds
 * @return
 */
public static Intent createTakeVideoIntent(Activity ctx, Uri savingUri, int durationInSeconds) {

    if (savingUri == null) {
        throw new NullPointerException("Uri cannot be null");
    }

    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    final PackageManager packageManager = ctx.getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, savingUri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationInSeconds);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("video/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    return chooserIntent;
}
 
Example 8
Source File: VideoModeActivity.java    From patrol-android with GNU General Public License v3.0 5 votes vote down vote up
private void dispatchTakeVideoIntent() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    dist = FilesUtils.getOutputExternalMediaFile(FilesUtils.MEDIA_TYPE_VIDEO);
    ContentValues value = new ContentValues();
    value.put(MediaStore.Video.Media.TITLE, dist.getName());
    value.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
    value.put(MediaStore.Video.Media.DATA, dist.getAbsolutePath());
    Uri videoUri = getContentResolver().insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, value);
    takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, videoUri);
    takeVideoIntent.putExtra(MediaStore.EXTRA_SCREEN_ORIENTATION, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    takeVideoIntent.putExtra(MediaStore.EXTRA_DURATION_LIMIT,60); //60 sec
    if (takeVideoIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takeVideoIntent, REQUEST_VIDEO_CAPTURE);
    }
}
 
Example 9
Source File: Web3WebviewModule.java    From react-native-web3-webview with MIT License 5 votes vote down vote up
private Intent getVideoIntent() {
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // @todo from experience, for Videos we get the data onActivityResult
    // so there's no need to store the Uri
    Uri outputVideoUri = getOutputUri(MediaStore.ACTION_VIDEO_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputVideoUri);
    return intent;
}
 
Example 10
Source File: ContentFragment.java    From droid-stealth with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Called when a MenuItem is clicked. Handles adding of items
 *
 * @param item
 * @return
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case R.id.content_add:
			Intent getContentIntent = FileUtils.createGetContentIntent();
			Intent intent = Intent.createChooser(getContentIntent, "Select a file");
			((HomeActivity) getActivity()).setRequestedActivity(true);
			startActivityForResult(intent, REQUEST_CHOOSER);
			return true;
		case R.id.content_image_capture:
			mTempResultFile = Utils.getRandomCacheFile(".jpg");
			Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
			cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile));
			((HomeActivity) getActivity()).setRequestedActivity(true);
			startActivityForResult(cameraIntent, CONTENT_REQUEST);
			return true;
		case R.id.content_video_capture:
			mTempResultFile = Utils.getRandomCacheFile(".mp4");
			Intent videoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
			videoIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile));
			((HomeActivity) getActivity()).setRequestedActivity(true);
			startActivityForResult(videoIntent, CONTENT_REQUEST);
			return true;
		case R.id.content_audio_capture:
			mTempResultFile = Utils.getRandomCacheFile(".3gp");
			((HomeActivity) getActivity()).setRequestedActivity(true);

			Intent audioIntent = new Intent(getActivity(), RecorderActivity.class);
			audioIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(mTempResultFile));
			startActivityForResult(audioIntent, CONTENT_REQUEST);
			return true;
		default:
			return super.onOptionsItemSelected(item);
	}
}
 
Example 11
Source File: MediaUtils.java    From q-municate-android with Apache License 2.0 5 votes vote down vote up
public static void startCameraVideoForResult(Fragment fragment) {
    Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (intent.resolveActivity(App.getInstance().getPackageManager()) == null) {
        return;
    }

    File videoFile = getTemporaryCameraFileVideo();
    Uri uri = getValidUri(videoFile, fragment.getContext());
    intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
    intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, ConstsCore.VIDEO_QUALITY_HIGH);
    intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, ConstsCore.MAX_RECORD_DURATION_IN_SEC);
    fragment.startActivityForResult(intent, CAMERA_VIDEO_REQUEST_CODE);
}
 
Example 12
Source File: Utils.java    From android-utils with MIT License 5 votes vote down vote up
/**
 * @param ctx
 * @param savingUri
 * @param durationInSeconds
 * @return
 * @deprecated Use {@link MediaUtils#createTakeVideoIntent(Activity, Uri, int)}
 * Creates an intent to take a video from camera or gallery or any other application that can
 * handle the intent.
 */
public static Intent createTakeVideoIntent(Activity ctx, Uri savingUri, int durationInSeconds) {

    if (savingUri == null) {
        throw new NullPointerException("Uri cannot be null");
    }

    final List<Intent> cameraIntents = new ArrayList<Intent>();
    final Intent captureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    final PackageManager packageManager = ctx.getPackageManager();
    final List<ResolveInfo> listCam = packageManager.queryIntentActivities(captureIntent, 0);
    for (ResolveInfo res : listCam) {
        final String packageName = res.activityInfo.packageName;
        final Intent intent = new Intent(captureIntent);
        intent.setComponent(new ComponentName(res.activityInfo.packageName, res.activityInfo.name));
        intent.setPackage(packageName);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, savingUri);
        intent.putExtra(MediaStore.EXTRA_DURATION_LIMIT, durationInSeconds);
        cameraIntents.add(intent);
    }

    // Filesystem.
    final Intent galleryIntent = new Intent();
    galleryIntent.setType("video/*");
    galleryIntent.setAction(Intent.ACTION_GET_CONTENT);

    // Chooser of filesystem options.
    final Intent chooserIntent = Intent.createChooser(galleryIntent, "Select Source");

    // Add the camera options.
    chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, cameraIntents.toArray(new Parcelable[]{}));

    return chooserIntent;
}
 
Example 13
Source File: VideoPicker.java    From androidnative.pri with Apache License 2.0 5 votes vote down vote up
static void takeVideo(Map message) {
    if (message.containsKey("broadcast")) {
        broadcast = (Boolean) message.get("broadcast");
    }

   Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
   Activity activity = org.qtproject.qt5.android.QtNative.activity();
   if (takeVideoIntent.resolveActivity(activity.getPackageManager()) != null) {
       activity.startActivityForResult(takeVideoIntent, TAKE_VIDEO_ACTION );
   }
}
 
Example 14
Source File: MainActivity.java    From Android-Basics-Codes with Artistic License 2.0 5 votes vote down vote up
public void click2(View v){
	//����ϵͳ�Դ����������
	Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
	//ָ����Ƶ����·��
	intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File("sdcard/haha.3gp")));
	//ָ����������
	intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
	startActivityForResult(intent, 20);
}
 
Example 15
Source File: RoomActivity.java    From matrix-android-console with Apache License 2.0 5 votes vote down vote up
/**
 * Launch the camera
 */
private void launchVideo() {
    final Intent captureIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    // lowest quality
    captureIntent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
    RoomActivity.this.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            startActivityForResult(captureIntent, TAKE_VIDEO);
        }
    });
}
 
Example 16
Source File: WebViewActivity.java    From mattermost-android-classic with Apache License 2.0 4 votes vote down vote up
private Intent createCamcorderIntent() {
    return new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
}
 
Example 17
Source File: XWalkFileChooser.java    From cordova-crosswalk-engine with Apache License 2.0 4 votes vote down vote up
public boolean showFileChooser(ValueCallback<Uri> uploadFile, String acceptType,
        String capture) {
    mFilePathCallback = uploadFile;

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(mActivity.getPackageManager()) != null) {
        // Create the File where the photo should go
        File photoFile = createImageFile();
        // Continue only if the File was successfully created
        if (photoFile != null) {
            mCameraPhotoPath = PATH_PREFIX + photoFile.getAbsolutePath();
            takePictureIntent.putExtra("PhotoPath", mCameraPhotoPath);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photoFile));
        } else {
            takePictureIntent = null;
        }
    }

    Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    Intent soundRecorder = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    Intent contentSelectionIntent = new Intent(Intent.ACTION_GET_CONTENT);
    contentSelectionIntent.addCategory(Intent.CATEGORY_OPENABLE);
    ArrayList<Intent> extraIntents = new ArrayList<Intent>();

    // A single mime type.
    if (!(acceptType.contains(SPLIT_EXPRESSION) || acceptType.contains(ANY_TYPES))) {
        if (capture.equals("true")) {
            if (acceptType.startsWith(IMAGE_TYPE)) {
                if (takePictureIntent != null) {
                    mActivity.startActivityForResult(takePictureIntent, INPUT_FILE_REQUEST_CODE);
                    Log.d(TAG, "Started taking picture");
                    return true;
                }
            } else if (acceptType.startsWith(VIDEO_TYPE)) {
                mActivity.startActivityForResult(camcorder, INPUT_FILE_REQUEST_CODE);
                Log.d(TAG, "Started camcorder");
                return true;
            } else if (acceptType.startsWith(AUDIO_TYPE)) {
                mActivity.startActivityForResult(soundRecorder, INPUT_FILE_REQUEST_CODE);
                Log.d(TAG, "Started sound recorder");
                return true;
            }
        } else {
            if (acceptType.startsWith(IMAGE_TYPE)) {
                if (takePictureIntent != null) {
                    extraIntents.add(takePictureIntent);
                }
                contentSelectionIntent.setType(ALL_IMAGE_TYPES);
            } else if (acceptType.startsWith(VIDEO_TYPE)) {
                extraIntents.add(camcorder);
                contentSelectionIntent.setType(ALL_VIDEO_TYPES);
            } else if (acceptType.startsWith(AUDIO_TYPE)) {
                extraIntents.add(soundRecorder);
                contentSelectionIntent.setType(ALL_AUDIO_TYPES);
            }
        }
    }

    // Couldn't resolve an accept type.
    if (extraIntents.isEmpty() && canWriteExternalStorage()) {
        if (takePictureIntent != null) {
            extraIntents.add(takePictureIntent);
        }
        extraIntents.add(camcorder);
        extraIntents.add(soundRecorder);
        contentSelectionIntent.setType(ANY_TYPES);
    }

    Intent chooserIntent = new Intent(Intent.ACTION_CHOOSER);
    chooserIntent.putExtra(Intent.EXTRA_INTENT, contentSelectionIntent);
    if (!extraIntents.isEmpty()) {
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                extraIntents.toArray(new Intent[] { }));
    }
    mActivity.startActivityForResult(chooserIntent, INPUT_FILE_REQUEST_CODE);
    Log.d(TAG, "Started chooser");
    return true;
}
 
Example 18
Source File: SelectFileDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates and starts an intent based on the passed fileTypes and capture value.
 * @param fileTypes MIME types requested (i.e. "image/*")
 * @param capture The capture value as described in http://www.w3.org/TR/html-media-capture/
 * @param window The WindowAndroid that can show intents
 */
@CalledByNative
private void selectFile(String[] fileTypes, boolean capture, WindowAndroid window) {
    mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes));
    mCapture = capture;

    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    mCameraOutputUri = Uri.fromFile(getFileForImageCapture());
    camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
    Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    Intent soundRecorder = new Intent(
            MediaStore.Audio.Media.RECORD_SOUND_ACTION);

    // Quick check - if the |capture| parameter is set and |fileTypes| has the appropriate MIME
    // type, we should just launch the appropriate intent. Otherwise build up a chooser based on
    // the accept type and then display that to the user.
    if (captureCamera()) {
        if (window.showIntent(camera, this, R.string.low_memory_error)) return;
    } else if (captureCamcorder()) {
        if (window.showIntent(camcorder, this, R.string.low_memory_error)) return;
    } else if (captureMicrophone()) {
        if (window.showIntent(soundRecorder, this, R.string.low_memory_error)) return;
    }

    Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
    ArrayList<Intent> extraIntents = new ArrayList<Intent>();
    if (!noSpecificType()) {
        // Create a chooser based on the accept type that was specified in the webpage. Note
        // that if the web page specified multiple accept types, we will have built a generic
        // chooser above.
        if (shouldShowImageTypes()) {
            extraIntents.add(camera);
            getContentIntent.setType(ALL_IMAGE_TYPES);
        } else if (shouldShowVideoTypes()) {
            extraIntents.add(camcorder);
            getContentIntent.setType(ALL_VIDEO_TYPES);
        } else if (shouldShowAudioTypes()) {
            extraIntents.add(soundRecorder);
            getContentIntent.setType(ALL_AUDIO_TYPES);
        }
    }

    if (extraIntents.isEmpty()) {
        // We couldn't resolve an accept type, so fallback to a generic chooser.
        getContentIntent.setType(ANY_TYPES);
        extraIntents.add(camera);
        extraIntents.add(camcorder);
        extraIntents.add(soundRecorder);
    }

    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            extraIntents.toArray(new Intent[] { }));

    chooser.putExtra(Intent.EXTRA_INTENT, getContentIntent);

    if (!window.showIntent(chooser, this, R.string.low_memory_error)) {
        onFileNotSelected();
    }
}
 
Example 19
Source File: SelectFileDialog.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Creates and starts an intent based on the passed fileTypes and capture value.
 * @param fileTypes MIME types requested (i.e. "image/*")
 * @param capture The capture value as described in http://www.w3.org/TR/html-media-capture/
 * @param window The WindowAndroid that can show intents
 */
@CalledByNative
private void selectFile(String[] fileTypes, boolean capture, WindowAndroid window) {
    mFileTypes = new ArrayList<String>(Arrays.asList(fileTypes));
    mCapture = capture;

    Intent chooser = new Intent(Intent.ACTION_CHOOSER);
    Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    mCameraOutputUri = Uri.fromFile(getFileForImageCapture());
    camera.putExtra(MediaStore.EXTRA_OUTPUT, mCameraOutputUri);
    Intent camcorder = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    Intent soundRecorder = new Intent(
            MediaStore.Audio.Media.RECORD_SOUND_ACTION);

    // Quick check - if the |capture| parameter is set and |fileTypes| has the appropriate MIME
    // type, we should just launch the appropriate intent. Otherwise build up a chooser based on
    // the accept type and then display that to the user.
    if (captureCamera()) {
        if (window.showIntent(camera, this, R.string.low_memory_error)) return;
    } else if (captureCamcorder()) {
        if (window.showIntent(camcorder, this, R.string.low_memory_error)) return;
    } else if (captureMicrophone()) {
        if (window.showIntent(soundRecorder, this, R.string.low_memory_error)) return;
    }

    Intent getContentIntent = new Intent(Intent.ACTION_GET_CONTENT);
    getContentIntent.addCategory(Intent.CATEGORY_OPENABLE);
    ArrayList<Intent> extraIntents = new ArrayList<Intent>();
    if (!noSpecificType()) {
        // Create a chooser based on the accept type that was specified in the webpage. Note
        // that if the web page specified multiple accept types, we will have built a generic
        // chooser above.
        if (shouldShowImageTypes()) {
            extraIntents.add(camera);
            getContentIntent.setType(ALL_IMAGE_TYPES);
        } else if (shouldShowVideoTypes()) {
            extraIntents.add(camcorder);
            getContentIntent.setType(ALL_VIDEO_TYPES);
        } else if (shouldShowAudioTypes()) {
            extraIntents.add(soundRecorder);
            getContentIntent.setType(ALL_AUDIO_TYPES);
        }
    }

    if (extraIntents.isEmpty()) {
        // We couldn't resolve an accept type, so fallback to a generic chooser.
        getContentIntent.setType(ANY_TYPES);
        extraIntents.add(camera);
        extraIntents.add(camcorder);
        extraIntents.add(soundRecorder);
    }

    chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS,
            extraIntents.toArray(new Intent[] { }));

    chooser.putExtra(Intent.EXTRA_INTENT, getContentIntent);

    if (!window.showIntent(chooser, this, R.string.low_memory_error)) {
        onFileNotSelected();
    }
}
 
Example 20
Source File: VideoCaptureIntentTest.java    From Camera2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    mIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
}