Java Code Examples for android.content.pm.PackageManager.hasSystemFeature()

The following are Jave code examples for showing how to use hasSystemFeature() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 设备是否有相机
 *
 * @param context
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 2
Project: Android_watch_magpie   File: MainActivity.java   View Source Code Vote up 6 votes
/**
     * Used to get if the device has a speacker
     * @return
     */
    public boolean hasSpeacker()
    {
        PackageManager packageManager = this.getPackageManager();
        AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);

// Check whether the device has a speaker.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            // Check FEATURE_AUDIO_OUTPUT to guard against false positives.
            if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
                return false;
            }

            AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
            for (AudioDeviceInfo device : devices) {
                if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                    return true;
                }
            }
        }
        return false;
    }
 
Example 3
Project: QMUI_Android   File: QMUIDisplayHelper.java   View Source Code Vote up 6 votes
public static final boolean hasCamera(Context context) {
    if (sHasCamera == null) {
        PackageManager pckMgr = context.getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        flag2 = flag || flag1;
        sHasCamera = flag2;
    }
    return sHasCamera;
}
 
Example 4
Project: yyox   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 设备是否有相机
 *
 * @param context
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 5
Project: Review-   File: TDevice.java   View Source Code Vote up 6 votes
public static final boolean hasCamera() {
    if (_hasCamera == null) {
        PackageManager pckMgr = BaseApplication.context()
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 6
Project: PicShow-zhaipin   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 设备是否有相机
 *
 * @param context
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 7
Project: MVPArms_Fragment-fragment   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 设备是否有相机
 *
 * @param context
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 8
Project: MoligyMvpArms   File: DeviceUtils.java   View Source Code Vote up 6 votes
/**
 * 设备是否有相机
 *
 * @param context
 * @return
 */
public static final boolean hasCamera(Context context) {
    if (_hasCamera == null) {
        PackageManager pckMgr = context
                .getPackageManager();
        boolean flag = pckMgr
                .hasSystemFeature("android.hardware.camera.front");
        boolean flag1 = pckMgr.hasSystemFeature("android.hardware.camera");
        boolean flag2;
        if (flag || flag1)
            flag2 = true;
        else
            flag2 = false;
        _hasCamera = Boolean.valueOf(flag2);
    }
    return _hasCamera.booleanValue();
}
 
Example 9
Project: q-mail   File: MessageWebView.java   View Source Code Vote up 5 votes
/**
 * Disable on-screen zoom controls on devices that support zooming via pinch-to-zoom.
 */
private void disableDisplayZoomControls() {
    PackageManager pm = getContext().getPackageManager();
    boolean supportsMultiTouch =
            pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH) ||
            pm.hasSystemFeature(PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT);

    getSettings().setDisplayZoomControls(!supportsMultiTouch);
}
 
Example 10
Project: RoadLab-Pro   File: GpsManager.java   View Source Code Vote up 5 votes
public boolean isGpsAvailable(final Context context) {
    if (gpsAvailable == null) {
        final PackageManager packageManager = context.getPackageManager();
        gpsAvailable = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    }
    return gpsAvailable;
}
 
Example 11
Project: react-native-google-fit   File: StepSensor.java   View Source Code Vote up 5 votes
public boolean hasStepCounter() {

        PackageManager pm = activity.getPackageManager();

        int currentApiVersion = Build.VERSION.SDK_INT;
        // Check that the device supports the step counter and detector sensors
        return currentApiVersion >= 19
                && pm.hasSystemFeature (PackageManager.FEATURE_SENSOR_STEP_COUNTER)
                && pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_STEP_DETECTOR);

    }
 
Example 12
Project: sample-tensorflow-imageclassifier   File: ImageClassifierActivity.java   View Source Code Vote up 5 votes
/**
 * @return true if this device is running Android Things.
 *
 * Source: https://stackoverflow.com/a/44171734/112705
 */
private boolean isAndroidThingsDevice(Context context) {
    // We can't use PackageManager.FEATURE_EMBEDDED here as it was only added in API level 26,
    // and we currently target a lower minSdkVersion
    final PackageManager pm = context.getPackageManager();
    boolean isRunningAndroidThings = pm.hasSystemFeature("android.hardware.type.embedded");
    Log.d(TAG, "isRunningAndroidThings: " + isRunningAndroidThings);
    return isRunningAndroidThings;
}
 
Example 13
Project: phonk   File: PUI.java   View Source Code Vote up 5 votes
private boolean check(String what, String feature, String permission) {
    boolean ret = false;

    PackageManager pm = getContext().getPackageManager();

    // check if available
    if (!pm.hasSystemFeature(feature)) throw new FeatureNotAvailableException(what);
    if (!getActivity().checkPermission(permission)) throw new PermissionNotGrantedException(what);
    ret = true;

    return ret;
}
 
Example 14
Project: GravityBox   File: Utils.java   View Source Code Vote up 5 votes
public static boolean hasProximitySensor(Context con) {
    if (mHasProximitySensor != null) return mHasProximitySensor;

    try {
        PackageManager pm = con.getPackageManager();
        mHasProximitySensor = pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_PROXIMITY);
        return mHasProximitySensor;
    } catch (Throwable t) {
        mHasProximitySensor = null;
        return false;
    }
}
 
Example 15
Project: Android-Location-Tracker   File: BaseApplication.java   View Source Code Vote up 4 votes
@Override
public void onCreate() {
    Configuration.sFilesDirMemory = getFilesDir();
    Configuration.sFilesDirPathMemory = getFilesDir().getPath();

    Configuration.sCacheDirMemory = getCacheDir();
    Configuration.sCacheDirPathMemory = getCacheDir().getPath();

    super.onCreate();
    LogHelper.verboseLog(TAG,
            "File name: \"" +
                    Thread.currentThread().getStackTrace()[2].getFileName() +
                    "\", Line number: " +
                    Thread.currentThread().getStackTrace()[2].getLineNumber() +
                    ", Class name: \"" +
                    Thread.currentThread().getStackTrace()[2].getClassName() +
                    "\", Method name: \"" +
                    Thread.currentThread().getStackTrace()[2].getMethodName() +
                    "\"");

    Configuration.sApplicationName = getString(R.string.app_name);

    Configuration.sOptionsTabFragmentPageTitle = getString(R.string.options);
    Configuration.sUpdatesTabFragmentPageTitle = getString(R.string.updates);

    Realm.init(this);

    RealmConfiguration realmConfiguration = new RealmConfiguration.Builder().build();

    try {
        Realm.setDefaultConfiguration(realmConfiguration);
    } catch (Exception e) {
        LogHelper.errorLog(TAG, e.getMessage());
        e.printStackTrace();
    }

    PackageManager packageManager = getPackageManager();

    if (packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION)) {
        LogHelper.infoLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION + "\" is available");

        Configuration.sIsFeatureLocationAvailable = true;
    } else {
        LogHelper.warnLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION + "\" is not available");

        Configuration.sIsFeatureLocationAvailable = false;
    }
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_NETWORK)) {
        LogHelper.infoLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION_NETWORK + "\" is available");

        Configuration.sIsFeatureLocationNetworkAvailable = true;
    } else {
        LogHelper.warnLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION_NETWORK + "\" is not available");

        Configuration.sIsFeatureLocationNetworkAvailable = false;
    }
    if (packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS)) {
        LogHelper.infoLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION_GPS + "\" is available");

        Configuration.sIsFeatureLocationGpsAvailable = true;
    } else {
        LogHelper.warnLog(TAG, "Feature \"" + PackageManager.FEATURE_LOCATION_GPS + "\" is not available");

        Configuration.sIsFeatureLocationGpsAvailable = false;
    }
}
 
Example 16
Project: bridgefy-android-samples   File: MainActivity.java   View Source Code Vote up 4 votes
public boolean isThingsDevice(Context context) {
    final PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature("android.hardware.type.embedded");
}
 
Example 17
Project: Watermark   File: CameraUtils.java   View Source Code Vote up 4 votes
/**
 * 判断设备是否有摄像头
 */
public static boolean hasCamera(Context context) {
    PackageManager packageManager = context.getPackageManager();
    return packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);

}
 
Example 18
Project: phonk   File: PLocation.java   View Source Code Vote up 4 votes
public boolean isAvailable() {
    PackageManager packageManager = getContext().getPackageManager();
    return packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
}
 
Example 19
Project: VanGogh   File: VanConfig.java   View Source Code Vote up 2 votes
/**
 * 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.
 */
public boolean hasCameraFeature(Context context) {
    PackageManager pm = context.getApplicationContext().getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
 
Example 20
Project: smart-lens   File: Utils.java   View Source Code Vote up 2 votes
/**
 * Check if the device has camera.
 *
 * @param context instance of the caller.
 * @return true if the device has camera.
 */
public static boolean checkIfHasCamera(@NonNull Context context) {
    PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}