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.hopestarter.wallet.ui.send.SweepWalletFragment.java

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

    reloadAction = menu.findItem(R.id.sweep_wallet_options_reload);
    scanAction = menu.findItem(R.id.sweep_wallet_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:cordova.plugins.Diagnostic.java

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

From source file:com.snappy.CameraCropActivity.java

public void startCamera() {
    // Check if camera exists
    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
        finish();/*w ww  . ja v a2s .c o m*/
    } else {
        try {
            long date = System.currentTimeMillis();
            String filename = DateFormat.format("yyyy-MM-dd_kk.mm.ss", date).toString() + ".jpg";
            _path = this.getExternalCacheDir() + "/" + filename;
            File file = new File(_path);
            //            File file = new File(getFileDir(getBaseContext()), filename);
            Uri outputFileUri = Uri.fromFile(file);
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(intent, CAMERA);
        } catch (Exception ex) {
            Toast.makeText(this, R.string.no_camera, Toast.LENGTH_LONG).show();
            finish();
        }

    }
}

From source file:org.protocoderrunner.apprunner.api.PDevice.java

@ProtoMethod(description = "Check if the device has camera", example = "")
public boolean hasCamera() {
    PackageManager pm = getContext().getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:com.czh.testmpeg.videorecord.CameraActivity.java

private boolean hasCamera(Context context) {
    if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else {//from  w w w .  j a  va  2 s. com
        return false;
    }
}

From source file:com.affectiva.affdexme.MainActivity.java

/**
 * We check to make sure the device has a front-facing camera.
 * If it does not, we obscure the app with a notice informing the user they cannot
 * use the app./* w w  w  . j  a v a 2s .c  o m*/
 */
void determineCameraAvailability() {
    PackageManager manager = getPackageManager();
    isFrontFacingCameraDetected = manager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
    isBackFacingCameraDetected = manager.hasSystemFeature(PackageManager.FEATURE_CAMERA);

    if (!isFrontFacingCameraDetected && !isBackFacingCameraDetected) {
        progressBar.setVisibility(View.INVISIBLE);
        pleaseWaitTextView.setVisibility(View.INVISIBLE);
        TextView notFoundTextView = (TextView) findViewById(R.id.not_found_textview);
        notFoundTextView.setVisibility(View.VISIBLE);
    }

    //set default camera settings
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    //restore the camera type settings
    String cameraTypeName = sharedPreferences.getString("cameraType",
            CameraDetector.CameraType.CAMERA_FRONT.name());
    if (cameraTypeName.equals(CameraDetector.CameraType.CAMERA_FRONT.name())) {
        cameraType = CameraDetector.CameraType.CAMERA_FRONT;
        mirrorPoints = true;
    } else {
        cameraType = CameraDetector.CameraType.CAMERA_BACK;
        mirrorPoints = false;
    }
}

From source file:com.p2p.misc.DeviceUtility.java

public Boolean hasCamera() {

    PackageManager pm = mactivity.getApplicationContext().getPackageManager();
    Boolean camera = pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);

    return camera;
}

From source file:com.paramedic.mobshaman.fragments.AccionesDetalleServicioFragment.java

/**
 * Start the camera by dispatching a camera intent.
 *///from  ww w .j  av  a 2  s . c  om
protected void dispatchTakePictureIntent(boolean isFinishingService) {

    // 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
    DetalleServicioActivity activity = (DetalleServicioActivity) 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());
            activity.setIsFinishingService(isFinishingService);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, activity.getCapturedImageURI());

            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}

From source file:com.rsmsa.accapp.MainActivity.java

/**
 * Checking device has camera hardware or not
 * *///w  w w  .ja  v  a 2 s .c o  m
private boolean isDeviceSupportCamera() {
    if (getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}

From source file:com.ushahidi.android.app.util.Util.java

/**
 * Checks that the device supports Camera.
 * //from   ww  w  . j a v a  2  s.  co  m
 * @param Context context - The calling activity's context.
 * @return boolean - True if it supports otherwise false.
 */
public static boolean deviceHasCamera(Context context) {

    PackageManager pm = context.getPackageManager();

    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        return true;
    } else {
        return false;
    }
}