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:org.openmidaas.app.activities.ScanFragment.java

private void showQRCodeScanner() {
    // check to see if a rear-camera is available
    if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Intent intentScan = new Intent(Intents.QR_CODE_INIT_INTENT);
        intentScan.putExtra("SCAN_MODE", "QR_CODE_MODE");
        intentScan.putExtra("SAVE_HISTORY", false);
        try {//from ww  w . j  ava2s .c om
            startActivityForResult(intentScan, SCAN_REQUEST);
        } catch (ActivityNotFoundException error) {
            showNoQRCodeScannersPresentDialog();
        }
    } else {
        showNoBackCameraPresentDialog();
    }
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.Tabs.Native.Native_CameraFragment.java

private boolean hasCamera(Context ctx) {
    return ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:org.fedorahosted.freeotp.main.ScanDialogFragment.java

public static boolean hasCamera(Context context) {
    PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:com.polyvi.xface.extension.devicecapability.XDeviceCapabilityExt.java

/**
 * ??/*from w  w w  .j av  a  2s .co m*/
 *
 * @param context
 * @return true:?false??
 */
private boolean isCameraAvailable(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:com.ultramegasoft.flavordex2.fragment.AbsPhotosFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mMediaReadable = Environment.getExternalStorageDirectory().canRead();
    if (!mMediaReadable) {
        return;//from  w ww  .  j a v a  2  s.  c o  m
    }
    setHasOptionsMenu(true);

    final Context context = getContext();
    if (context == null) {
        return;
    }
    mHasCamera = context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);

    if (savedInstanceState != null) {
        final ArrayList<PhotoHolder> photos = savedInstanceState.getParcelableArrayList(STATE_PHOTOS);
        if (photos != null) {
            mPhotos = photos;
        }
        mCapturedPhoto = savedInstanceState.getParcelable(STATE_CAPTURE_URI);
        final Uri loadingUri = savedInstanceState.getParcelable(STATE_LOADING_URI);
        if (loadingUri != null) {
            mPhotoLoader = new PhotoLoader(context, this, loadingUri);
            mPhotoLoader.execute();
        }
    }
}

From source file:com.monmonja.library.social.SocialNetworkDialogFragment.java

/** * Start the camera by dispatching a camera intent. */
protected void dispatchTakePictureIntent() {
    PackageManager packageManager = getActivity().getPackageManager();
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show();
        return;//from w  w  w. j  ava  2  s .c o m
    }

    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getActivity().getPackageManager()) != null) {
        try {
            File tempFile = getTempCaptureImgPath();
            mTempTakePicturePath = tempFile.getAbsolutePath();
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tempFile));
            startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        } catch (IOException ex) {

        }

    }
}

From source file:com.collectme.cordova.diagnostic.Diagnostic.java

public boolean isCameraEnabled() {
    PackageManager pm = this.cordova.getActivity().getPackageManager();
    boolean result = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
    return result;
}

From source file:org.qeo.android.security.OtcDialog.java

/**
 * isCameraAvailable check if the device has a camera for QR Code scanning.
 * //w  w w .j a va 2  s .c  om
 * @return boolean true if device has at least 1 camera
 */
private boolean isCameraAvailable(Context context) {
    return (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));
}

From source file:camera.AnotherCamera.java

/**
 * Start the camera by dispatching a camera intent.
 *//*  w ww .j  a v a 2  s. c  o  m*/
protected void dispatchTakePictureIntent() {

    // Check if there is a camera.
    Context context = getActivity();
    PackageManager packageManager = context.getPackageManager();
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA) == false) {
        Toast.makeText(getActivity(), "This device does not have a camera.", Toast.LENGTH_SHORT).show();
        return;
    }

    // Camera exists? Then proceed...
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    // Ensure that there's a camera activity to handle the intent
    CameraActivity activity = (CameraActivity) getActivity();
    if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
        // Create the File where the photo should go.
        // If you don't do this, you may get a crash in some devices.
        File photoFile = null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            Toast toast = Toast.makeText(activity, "There was a problem saving the photo...",
                    Toast.LENGTH_SHORT);
            toast.show();
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri fileUri = Uri.fromFile(photoFile);
            activity.setCapturedImageURI(fileUri);
            activity.setCurrentPhotoPath(fileUri.getPath());
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, activity.getCapturedImageURI());
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

From source file:mysteryinc.eagleeye.LiveLocatorFragment.java

private boolean deviceMissingCamera() {
    Context context = getActivity();
    PackageManager packageManager = context.getPackageManager();
    return !packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}