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:io.github.data4all.activity.CameraActivity.java

/**
 * This method looks whether the device has a camera and then returns a
 * boolean.//from www . j a  va 2s.  c om
 * 
 * @return boolean true if device has a camera, false otherwise
 */
private boolean isDeviceSupportCamera() {
    Log.d(TAG, "look if device has camera");
    return getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * checking if the hardware has a camera that can be used.
 *
 * @return True if camera, false if not.
 *//*from   www . ja  va2s .  c o  m*/

public boolean checkHasCamera(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:com.cw.litenote.DrawerActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //      System.out.println("DrawerActivity / onCreateOptionsMenu");
    mMenu = menu;//w w  w.  j  a va 2 s .com

    // inflate menu
    getMenuInflater().inflate(R.menu.main_menu, menu);

    // check camera feature
    PackageManager packageManager = this.getPackageManager();

    // camera image
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA))
        menu.findItem(R.id.ADD_NEW_IMAGE).setEnabled(false);

    // camera video
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA))
        menu.findItem(R.id.ADD_NEW_VIDEO).setEnabled(false);

    playOrStopMusicButton = menu.findItem(R.id.PLAY_OR_STOP_MUSIC);

    // show body
    mPref_show_note_attribute = getSharedPreferences("show_note_attribute", 0);
    if (mPref_show_note_attribute.getString("KEY_SHOW_BODY", "yes").equalsIgnoreCase("yes"))
        menu.findItem(R.id.SHOW_BODY).setIcon(R.drawable.ic_menu_collapse)
                .setTitle(R.string.preview_note_body_no);
    else
        menu.findItem(R.id.SHOW_BODY).setIcon(R.drawable.ic_menu_expand)
                .setTitle(R.string.preview_note_body_yes);

    // show draggable
    mPref_show_note_attribute = getSharedPreferences("show_note_attribute", 0);
    if (mPref_show_note_attribute.getString("KEY_ENABLE_DRAGGABLE", "no").equalsIgnoreCase("yes"))
        menu.findItem(R.id.ENABLE_NOTE_DRAG_AND_DROP).setIcon(R.drawable.ic_dragger_off)
                .setTitle(R.string.draggable_no);
    else
        menu.findItem(R.id.ENABLE_NOTE_DRAG_AND_DROP).setIcon(R.drawable.ic_dragger_on)
                .setTitle(R.string.draggable_yes);

    //
    // Group 1 sub_menu for drawer operation
    //

    // add sub_menu item: add drawer dragger  setting
    if (mPref_show_note_attribute.getString("KEY_ENABLE_DRAWER_DRAGGABLE", "no").equalsIgnoreCase("yes"))
        menu.findItem(R.id.ENABLE_DRAWER_DRAG_AND_DROP).setIcon(R.drawable.ic_dragger_off)
                .setTitle(R.string.draggable_no);
    else
        menu.findItem(R.id.ENABLE_DRAWER_DRAG_AND_DROP).setIcon(R.drawable.ic_dragger_on)
                .setTitle(R.string.draggable_yes);

    return super.onCreateOptionsMenu(menu);
}

From source file:cc.mintcoin.wallet.ui.SendCoinsFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.send_coins_fragment_options, menu);

    scanAction = menu.findItem(R.id.send_coins_options_scan);

    final PackageManager pm = activity.getPackageManager();
    scanAction.setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.bushstar.htmlcoin_android_wallet.ui.SendCoinsFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.send_coins_fragment_options, menu);

    scanAction = menu.findItem(R.id.send_coins_options_scan);
    emptyAction = menu.findItem(R.id.send_coins_options_empty);

    final PackageManager pm = activity.getPackageManager();
    scanAction.setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void getNewPicture(boolean checkPermission) {
    if (checkPermission) {
        askCameraPermission(false, new SafeRunnable() {
            @Override/*ww  w . ja  v  a  2  s .c o  m*/
            protected void safeRun() throws Exception {
                getNewPicture(false);
            }
        });
        return;
    }

    if (!setupUploadFile("jpg", true)) {
        return;
    }

    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedFile);
    galleryIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    galleryIntent.setType("image/*");

    final Intent chooserIntent = Intent.createChooser(galleryIntent,
            mActivity.getString(R.string.select_source));

    if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            && mMainService.isPermitted(Manifest.permission.CAMERA)) {
        Intent cameraIntent = ActivityUtils.buildTakePictureIntent(mActivity, mUriSavedFile, Facing.BACK);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { cameraIntent });
    }

    mActivity.startActivityForResult(chooserIntent, PICK_IMAGE);
}

From source file:com.mobicage.rogerthat.util.ui.SendMessageView.java

private void getNewVideo(boolean checkPermission) {
    if (checkPermission) {
        askCameraPermission(true, new SafeRunnable() {
            @Override/*from   w  w  w  .jav  a 2s.  com*/
            protected void safeRun() throws Exception {
                getNewVideo(false);
            }
        });
        return;
    }

    if (!setupUploadFile("mp4", true)) {
        return;
    }

    Intent galleryIntent = new Intent(Intent.ACTION_PICK,
            android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    galleryIntent.putExtra(MediaStore.EXTRA_OUTPUT, mUriSavedFile);
    galleryIntent.setType(AttachmentViewerActivity.CONTENT_TYPE_VIDEO_MP4);

    final Intent chooserIntent = Intent.createChooser(galleryIntent,
            mActivity.getString(R.string.select_source));
    if (mActivity.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            && mMainService.isPermitted(Manifest.permission.CAMERA)) {
        Intent cameraIntent = ActivityUtils.buildMakeVideoIntent(mActivity, mUriSavedFile);
        chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { cameraIntent });
    }

    mActivity.startActivityForResult(chooserIntent, PICK_VIDEO);
}

From source file:org.hopestarter.wallet.ui.send.SendCoinsFragment.java

@Override
public void onPrepareOptionsMenu(final Menu menu) {
    final MenuItem scanAction = menu.findItem(R.id.send_coins_options_scan);
    final PackageManager pm = activity.getPackageManager();
    scanAction.setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));
    scanAction.setEnabled(state == State.INPUT);

    super.onPrepareOptionsMenu(menu);
}

From source file:com.softanalle.scma.MainActivity.java

/** 
 * Check if this device has a camera//from  w w w . j av  a 2  s .c  o  m
 * @param context The application context to be used
 */
private boolean checkCameraHardware(Context context) {
    logger.debug("checkCameraHardware()");
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}

From source file:com.aimfire.demo.CameraActivity.java

/** 
 * we had camera permission, and use-feature in manifest, but we don't require it, so 
 * check to make sure it exists/*  w  w  w  . ja  va 2 s.c om*/
 */
private boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}