Example usage for android.content.pm PackageManager FEATURE_CAMERA

List of usage examples for android.content.pm PackageManager FEATURE_CAMERA

Introduction

In this page you can find the example usage for android.content.pm PackageManager FEATURE_CAMERA.

Prototype

String FEATURE_CAMERA

To view the source code for android.content.pm PackageManager FEATURE_CAMERA.

Click Source Link

Document

Feature for #getSystemAvailableFeatures and #hasSystemFeature : The device has a camera facing away from the screen.

Usage

From source file:it.feio.android.omninotes.DetailFragment.java

private void takePhoto() {
    // Checks for camera app available
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, intent, new String[] { PackageManager.FEATURE_CAMERA })) {
        mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);

        return;//from   w  w  w .  j  a v a2 s .  c om
    }
    // Checks for created file validity
    File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_IMAGE_EXT);
    if (f == null) {
        mainActivity.showMessage(R.string.error, ONStyle.ALERT);
        return;
    }
    // Launches intent
    attachmentUri = Uri.fromFile(f);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    startActivityForResult(intent, TAKE_PHOTO);
}

From source file:it.feio.android.omninotes.DetailFragment.java

private void takeVideo() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, takeVideoIntent,
            new String[] { PackageManager.FEATURE_CAMERA })) {
        mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);

        return;//from  ww w .ja  va2 s  . c  om
    }
    // File is stored in custom ON folder to speedup the attachment
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_VIDEO_EXT);
        if (f == null) {
            mainActivity.showMessage(R.string.error, ONStyle.ALERT);

            return;
        }
        attachmentUri = Uri.fromFile(f);
        takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    }
    String maxVideoSizeStr = "".equals(prefs.getString("settings_max_video_size", "")) ? "0"
            : prefs.getString("settings_max_video_size", "");
    int maxVideoSize = Integer.parseInt(maxVideoSizeStr);
    takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, Long.valueOf(maxVideoSize * 1024 * 1024));
    startActivityForResult(takeVideoIntent, TAKE_VIDEO);
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void takePhoto() {
    // Checks for camera app available
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, intent, new String[] { PackageManager.FEATURE_CAMERA })) {
        //mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);
        Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT).show();

        return;/*  w  w w .j av a2 s. com*/
    }
    // Checks for created file validity
    File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_IMAGE_EXT);
    if (f == null) {
        Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show();
        //mainActivity.showMessage(R.string.error, ONStyle.ALERT);
        return;
    }
    // Launches intent
    attachmentUri = Uri.fromFile(f);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    startActivityForResult(intent, TAKE_PHOTO);
}

From source file:com.dycody.android.idealnote.DetailFragment.java

private void takeVideo() {
    Intent takeVideoIntent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    if (!IntentChecker.isAvailable(mainActivity, takeVideoIntent,
            new String[] { PackageManager.FEATURE_CAMERA })) {
        //mainActivity.showMessage(R.string.feature_not_available_on_this_device, ONStyle.ALERT);
        Toast.makeText(getActivity(), R.string.feature_not_available_on_this_device, Toast.LENGTH_SHORT).show();

        return;/*from  ww w.jav  a 2 s .  com*/
    }
    // File is stored in custom ON folder to speedup the attachment
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        File f = StorageHelper.createNewAttachmentFile(mainActivity, Constants.MIME_TYPE_VIDEO_EXT);
        if (f == null) {
            //mainActivity.showMessage(R.string.error, ONStyle.ALERT);
            Toast.makeText(getActivity(), R.string.error, Toast.LENGTH_SHORT).show();

            return;
        }
        attachmentUri = Uri.fromFile(f);
        takeVideoIntent.putExtra(MediaStore.EXTRA_OUTPUT, attachmentUri);
    }
    String maxVideoSizeStr = "".equals(prefs.getString("settings_max_video_size", "")) ? "0"
            : prefs.getString("settings_max_video_size", "");
    int maxVideoSize = parseInt(maxVideoSizeStr);
    takeVideoIntent.putExtra(MediaStore.EXTRA_SIZE_LIMIT, Long.valueOf(maxVideoSize * 1024 * 1024));
    startActivityForResult(takeVideoIntent, TAKE_VIDEO);
}

From source file:org.thoughtcrime.securesms.conversation.ConversationActivity.java

private void initializeViews() {
    ActionBar supportActionBar = getSupportActionBar();
    if (supportActionBar == null)
        throw new AssertionError();

    titleView = (ConversationTitleView) supportActionBar.getCustomView();
    buttonToggle = ViewUtil.findById(this, R.id.button_toggle);
    sendButton = ViewUtil.findById(this, R.id.send_button);
    attachButton = ViewUtil.findById(this, R.id.attach_button);
    composeText = ViewUtil.findById(this, R.id.embedded_text_editor);
    charactersLeft = ViewUtil.findById(this, R.id.space_left);
    emojiDrawerStub = ViewUtil.findStubById(this, R.id.emoji_drawer_stub);
    unblockButton = ViewUtil.findById(this, R.id.unblock_button);
    makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button);
    registerButton = ViewUtil.findById(this, R.id.register_button);
    composePanel = ViewUtil.findById(this, R.id.bottom_panel);
    container = ViewUtil.findById(this, R.id.layout_container);
    reminderView = ViewUtil.findStubById(this, R.id.reminder_stub);
    unverifiedBannerView = ViewUtil.findStubById(this, R.id.unverified_banner_stub);
    groupShareProfileView = ViewUtil.findStubById(this, R.id.group_share_profile_view_stub);
    quickAttachmentToggle = ViewUtil.findById(this, R.id.quick_attachment_toggle);
    inlineAttachmentToggle = ViewUtil.findById(this, R.id.inline_attachment_container);
    inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
    searchNav = ViewUtil.findById(this, R.id.conversation_search_nav);

    ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
    ImageButton inlineAttachmentButton = ViewUtil.findById(this, R.id.inline_attachment_button);

    container.addOnKeyboardShownListener(this);
    inputPanel.setListener(this);
    inputPanel.setMediaListener(this);

    attachmentTypeSelector = null;/*from w w  w  .  ja  v a  2 s. c  om*/
    attachmentManager = new AttachmentManager(this, this);
    audioRecorder = new AudioRecorder(this);
    typingTextWatcher = new TypingStatusTextWatcher();

    SendButtonListener sendButtonListener = new SendButtonListener();
    ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();

    composeText.setOnEditorActionListener(sendButtonListener);
    composeText.setCursorPositionChangedListener(this);
    attachButton.setOnClickListener(new AttachButtonListener());
    attachButton.setOnLongClickListener(new AttachButtonLongClickListener());
    sendButton.setOnClickListener(sendButtonListener);
    sendButton.setEnabled(true);
    sendButton.addOnTransportChangedListener((newTransport, manuallySelected) -> {
        calculateCharactersRemaining();
        updateLinkPreviewState();
        composeText.setTransport(newTransport);
        buttonToggle.getBackground().setColorFilter(newTransport.getBackgroundColor(), Mode.MULTIPLY);
        buttonToggle.getBackground().invalidateSelf();
        if (manuallySelected)
            recordTransportPreference(newTransport);
    });

    titleView.setOnClickListener(v -> handleConversationSettings());
    titleView.setOnLongClickListener(v -> handleDisplayQuickContact());
    titleView.setOnBackClickedListener(view -> super.onBackPressed());
    unblockButton.setOnClickListener(v -> handleUnblock());
    makeDefaultSmsButton.setOnClickListener(v -> handleMakeDefaultSms());
    registerButton.setOnClickListener(v -> handleRegisterForSignal());

    composeText.setOnKeyListener(composeKeyPressedListener);
    composeText.addTextChangedListener(composeKeyPressedListener);
    composeText.setOnEditorActionListener(sendButtonListener);
    composeText.setOnClickListener(composeKeyPressedListener);
    composeText.setOnFocusChangeListener(composeKeyPressedListener);

    if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            && Camera.getNumberOfCameras() > 0) {
        quickCameraToggle.setVisibility(View.VISIBLE);
        quickCameraToggle.setOnClickListener(new QuickCameraToggleListener());
    } else {
        quickCameraToggle.setVisibility(View.GONE);
    }

    searchNav.setEventListener(this);

    inlineAttachmentButton.setOnClickListener(v -> handleAddAttachment());
}

From source file:org.cryptsecure.Utility.java

/**
 * Checks if a is camera available on the current device.
 * //from ww  w.  j a v a 2 s  . com
 * @param context
 *            the context
 * @return true, if is camera available
 */
public static boolean isCameraAvailable(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA));
}