Example usage for android.content.pm PackageManager hasSystemFeature

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

Introduction

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

Prototype

public abstract boolean hasSystemFeature(String name);

Source Link

Document

Check whether the given feature name is one of the available features as returned by #getSystemAvailableFeatures() .

Usage

From source file:Main.java

public static boolean doesDeviceSupportCameras(@NonNull Context context) {

    final PackageManager packageManager = context.getPackageManager();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        return packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
    } else {//from  w  w w .j  a  va 2s .  c  om
        return packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
                || packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
    }
}

From source file:com.nuvolect.securesuite.util.PermissionUtil.java

/**
 * Request permissions during application first time install.
 * Method will not ask for phone state if it is not a phone.
 * @param act/*from ww w . ja v a 2  s.c  om*/
 */
public static void requestFirstTimePermissions(Activity act) {

    ArrayList<String> permissionRequests = new ArrayList<String>();
    PackageManager pm = act.getPackageManager();

    if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {

        if (!hasPermission(act, android.Manifest.permission.READ_PHONE_STATE)) {

            permissionRequests.add(Manifest.permission.READ_PHONE_STATE);
        }
    }
    if (!hasPermission(act, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)) {

        permissionRequests.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
    }

    if (permissionRequests.size() > 0) {

        String[] requests = new String[permissionRequests.size()];
        requests = permissionRequests.toArray(requests);
        ActivityCompat.requestPermissions(act, requests, CConst.NO_ACTION);
    }
}

From source file:com.xbm.android.matisse.internal.utils.MediaStoreCompat.java

/**
 * Checks whether the device has a camera feature or not.
 *
 * @param context a context to check for camera feature.
 * @return true if the device has a camera feature. false otherwise.
 *//*from   w ww. j  av  a  2 s . c om*/
public static boolean hasCameraFeature(Context context) {
    PackageManager pm = context.getApplicationContext().getPackageManager();
    return pm.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.phonemetra.account.util.AccountUtils.java

public static boolean hasTelephony(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}

From source file:com.android.contacts.activities.RequestPermissionsActivity.java

private static String[] getPermissions(PackageManager packageManager) {
    if (sRequiredPermissions == null) {
        final List<String> permissions = new ArrayList<>();
        // Contacts group
        permissions.add(permission.GET_ACCOUNTS);
        permissions.add(permission.READ_CONTACTS);
        permissions.add(permission.WRITE_CONTACTS);

        if (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            // Phone group
            // These are only used in a few places such as QuickContactActivity and
            // ImportExportDialogFragment.  We work around missing this permission when
            // telephony is not available on the device (i.e. on tablets).
            permissions.add(permission.CALL_PHONE);
            permissions.add(permission.READ_CALL_LOG);
            permissions.add(permission.READ_PHONE_STATE);
        }//  w  w w  .  j a  va2 s  .c om
        sRequiredPermissions = permissions.toArray(new String[0]);
    }
    return sRequiredPermissions;
}

From source file:org.cyanogenmod.theme.chooser.WallpaperAndIconPreviewFragment.java

public static ComponentName[] getIconComponents(Context context) {

    if (sIconComponents == null || sIconComponents.length == 0) {
        sIconComponents = new ComponentName[] { COMPONENT_DIALER, COMPONENT_MESSAGING, COMPONENT_CAMERA,
                COMPONENT_BROWSER };/*from  w w  w.jav a  2  s . c om*/

        PackageManager pm = context.getPackageManager();

        // if device does not have telephony replace dialer and mms
        if (!pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            sIconComponents[0] = COMPONENT_CALENDAR;
            sIconComponents[1] = COMPONENT_GALERY;
        }

        if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            sIconComponents[2] = COMPONENT_SETTINGS;
        } else {
            // decide on which camera icon to use
            try {
                if (pm.getPackageInfo(CAMERA_NEXT_PACKAGE, 0) != null) {
                    sIconComponents[2] = COMPONENT_CAMERANEXT;
                }
            } catch (NameNotFoundException e) {
                // default to COMPONENT_CAMERA
            }
        }

    }

    return sIconComponents;
}

From source file:Main.java

/**
 * Decides weather the current soft- and hardware setup allows to use hardware step detection
 * @param pm An instance of the android PackageManager
 * @return true if hardware step detection can be used otherwise false
 *//* w  w w  .  j av  a2 s  .co m*/
public static boolean supportsStepDetector(PackageManager pm) {
    // (Hardware) step detection was introduced in KitKat (4.4 / API 19)
    // https://developer.android.com/about/versions/android-4.4.html
    return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
            // In addition to the system version
            // the hardware step detection is not supported on every device
            // let's check the device's ability.
            && pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_COUNTER)
            && pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR);

}

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

/**
 * Checks that the device supports Camera.
 * /*from w w w .  j a  va  2s . 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;
    }
}

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

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

    PackageManager pm = context.getPackageManager();

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