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

The following examples show how to use android.content.pm.PackageManager#hasSystemFeature() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: WifiUtils   File: LocationUtils.java    License: Apache License 2.0 7 votes vote down vote up
public static int checkLocationAvailability(@NonNull final Context context) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        final PackageManager packMan = context.getPackageManager();
        if (packMan.hasSystemFeature(PackageManager.FEATURE_LOCATION)) {
            if (!isLocationEnabled(context)) {
                Log.d(TAG, "Location DISABLED");
                return LOCATION_DISABLED;
            }
        } else {
            Log.d(TAG, "NO GPS SENSOR");
            return NO_LOCATION_AVAILABLE;
        }
    }
    Log.d(TAG, "GPS GOOD TO GO");
    return GOOD_TO_GO;
}
 
Example 2
Source Project: AndPermission   File: LocationFineTest.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean test() throws Throwable {
    LocationManager locationManager = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getProviders(true);
    boolean gpsProvider = providers.contains(LocationManager.GPS_PROVIDER);
    boolean passiveProvider = providers.contains(LocationManager.PASSIVE_PROVIDER);
    if (gpsProvider || passiveProvider) {
        return true;
    }

    PackageManager packageManager = mContext.getPackageManager();
    boolean gpsHardware = packageManager.hasSystemFeature(PackageManager.FEATURE_LOCATION_GPS);
    if (!gpsHardware) return true;

    return !locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
 
Example 3
@Override
protected void onCreate(Bundle bundle) {
    PackageManager pm = getPackageManager();
    if (!pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN)) {
        touchscreen = false;
    }

    applyTheme();
    applyFullscreen();
    super.onCreate(bundle);
    startService(new Intent(this, DownloadService.class));
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (getIntent().hasExtra(Constants.FRAGMENT_POSITION)) {
        lastSelectedPosition = getIntent().getIntExtra(Constants.FRAGMENT_POSITION, 0);
    }

    if (preferencesListener == null) {
        Util.getPreferences(this).registerOnSharedPreferenceChangeListener(preferencesListener);
    }

    if (ContextCompat.checkSelfPermission(this, permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{permission.WRITE_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE);
    }
}
 
Example 4
Source Project: Lassi-Android   File: CameraUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Determines whether the device has valid camera sensors, so the library
 * can be used.
 *
 * @param context a valid Context
 * @return whether device has cameras
 */
@SuppressWarnings("WeakerAccess")
public static boolean hasCameras(@NonNull Context context) {
    PackageManager manager = context.getPackageManager();
    // There's also FEATURE_CAMERA_EXTERNAL , should we support it?
    return manager.hasSystemFeature(PackageManager.FEATURE_CAMERA)
            || manager.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT);
}
 
Example 5
Source Project: react-native-google-fit   File: StepSensor.java    License: MIT License 5 votes vote down vote up
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 6
public static boolean isAvailable(Context ctx, Intent intent, String[] features) {
    final PackageManager mgr = ctx.getPackageManager();
    List<ResolveInfo> list = mgr.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
    boolean res = list.size() > 0;
    if (features != null) {
        for (String feature : features) {
            res = res && mgr.hasSystemFeature(feature);
        }
    }
    return res;
}
 
Example 7
@Override
public void onStart() {
    final Context context = getContext();
    mNotifManager = context.getSystemService(NotificationManager.class);

    mCacheFileDeletedObserver = new CacheFileDeletedObserver();
    mCacheFileDeletedObserver.startWatching();

    // Ensure that the notification channel is set up
    PackageManager packageManager = context.getPackageManager();
    boolean isTv = packageManager.hasSystemFeature(PackageManager.FEATURE_LEANBACK);

    if (isTv) {
        mNotifManager.createNotificationChannel(new NotificationChannel(
                TV_NOTIFICATION_CHANNEL_ID,
                context.getString(
                    com.android.internal.R.string.device_storage_monitor_notification_channel),
                NotificationManager.IMPORTANCE_HIGH));
    }

    publishBinderService(SERVICE, mRemoteService);
    publishLocalService(DeviceStorageMonitorInternal.class, mLocalService);

    // Kick off pass to examine storage state
    mHandler.removeMessages(MSG_CHECK);
    mHandler.obtainMessage(MSG_CHECK).sendToTarget();
}
 
Example 8
public boolean requestPicture() {
    PackageManager pm = mActivity.getPackageManager();
    if (safeToTakePicture) {

        safeToTakePicture = false;

        try {
            if(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS)){
                mCamera.autoFocus(new Camera.AutoFocusCallback() {
                    @Override
                    public void onAutoFocus(boolean success, Camera camera) {
                        if (success) {
                            mCamera.takePicture(null, null, pCallback);
                            blinkScreen();
                            blinkScreenAndShutterSound();
                        }
                        if (attemptToFocus) {
                            return;
                        } else {
                            attemptToFocus = true;
                        }
                    }
                });
            }else{
                mCamera.takePicture(null,null,pCallback);
                blinkScreen();
                blinkScreenAndShutterSound();
            }
        }catch(Exception e){
            waitSpinnerInvisible();
        }finally {
            waitSpinnerInvisible();
        }
        return true;
    }
    return false;
}
 
Example 9
Source Project: FairEmail   File: Helper.java    License: GNU General Public License v3.0 5 votes vote down vote up
static boolean hasWebView(Context context) {
    PackageManager pm = context.getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_WEBVIEW))
        try {
            new WebView(context);
            return true;
        } catch (Throwable ex) {
            return false;
        }
    else
        return false;
}
 
Example 10
/**
 * Check if we have a barometer. Use info to disable menu items, choose to
 * run the service or not, etc.
 */
private boolean checkBarometer() {
	PackageManager packageManager = this.getPackageManager();
	hasBarometer = packageManager
			.hasSystemFeature(PackageManager.FEATURE_SENSOR_BAROMETER);
	return hasBarometer;
}
 
Example 11
Source Project: StepSensor   File: SensorStepServiceManager.java    License: MIT License 5 votes vote down vote up
/**
 * Allows to know if the {@link android.hardware.Sensor#TYPE_STEP_COUNTER} is available for the device or not
 *
 * @return true if the feature is available, false otherwise.
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static boolean isStepCounterFeatureAvailable(PackageManager pm) {   // Require at least Android KitKat
    int currentApiVersion = (int) 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
/**
 * Checks the underlying stack to see if BLE is supported on the phone.
 */
public final boolean isBleSupported()
{
	PackageManager pm = m_context.getPackageManager();
	boolean hasBLE = pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE);

	return hasBLE;
}
 
Example 13
Source Project: litho   File: DoubleMeasureFixUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Correction for an Android bug on some devices with "special" densities where the system will
 * double-measure with slightly different widths in the same traversal. See
 * https://issuetracker.google.com/issues/73804230 for more details.
 *
 * <p>This hits Litho extra-hard because we create {@link LayoutState}s in measure in many places,
 * so we try to correct for it here by replacing the widthSpec given to us from above with what we
 * think the correct one is. Even though the double measure will still happen, the incorrect width
 * will not propagate to any vertical RecyclerViews contained within.
 */
public static int correctWidthSpecForAndroidDoubleMeasureBug(
    Resources resources, PackageManager packageManager, int widthSpec) {
  final @SizeSpec.MeasureSpecMode int mode = SizeSpec.getMode(widthSpec);
  if (mode == SizeSpec.UNSPECIFIED) {
    return widthSpec;
  }

  // Will cache the device type to avoid repetitive package manager calls.
  if (deviceType == UNSET) {
    try {
      // Required to determine whether device used is a Chromebook.
      // See https://stackoverflow.com/questions/39784415/ for details.
      deviceType =
          packageManager.hasSystemFeature("org.chromium.arc.device_management")
              ? CHROMEBOOK
              : NORMAL;
    } catch (RuntimeException e) {
      // To catch RuntimeException("Package manager has died") that can occur on some version of
      // Android, when the remote PackageManager is unavailable. I suspect this sometimes occurs
      // when the App is being reinstalled.
      deviceType = NORMAL;
    }
  }

  final Configuration configuration = resources.getConfiguration();
  final DisplayMetrics displayMetrics = resources.getDisplayMetrics();
  final float screenDensity = displayMetrics.density;
  final float screenWidthDp = configuration.screenWidthDp;
  // If device used is a Chromebook we need to use the window size instead of the screen size to
  // avoid layout issues.
  final int screenWidthPx =
      (deviceType == CHROMEBOOK)
          ? (int) (screenWidthDp * screenDensity + 0.5f)
          : displayMetrics.widthPixels;

  // NB: Logic taken from ViewRootImpl#dipToPx
  final int calculatedScreenWidthPx = (int) (screenDensity * screenWidthDp + 0.5f);

  if (screenWidthPx != calculatedScreenWidthPx
      && calculatedScreenWidthPx == SizeSpec.getSize(widthSpec)) {
    return SizeSpec.makeSizeSpec(screenWidthPx, mode);
  }

  return widthSpec;
}
 
Example 14
private boolean isSupportTelePhony() {
    PackageManager packageManager = mContext.getPackageManager();
    return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}
 
Example 15
/**
 * Determine if the device has a camera.
 *
 * @return true if the device has a camera.
 */
public static boolean hasCamera() {
	PackageManager pm = Application.getAppContext().getPackageManager();

	return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}
 
Example 16
Source Project: FairEmail   File: Helper.java    License: GNU General Public License v3.0 4 votes vote down vote up
static boolean canPrint(Context context) {
    PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_PRINTING);
}
 
Example 17
private void displayNotCompatibleDialog() {
    // check if displayed in this app run
    if (showNotCompatibleDialog) {
        // check if not disabled in preferences
        boolean showCompatibilityWarningEnabled = MyApplication.getPreferencesProvider().getShowCompatibilityWarning();
        if (showCompatibilityWarningEnabled) {
            TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
            // check if device contains telephony hardware (some tablets doesn't report even if have)
            // NOTE: in the future this may need to be expanded when new specific features appear
            PackageManager packageManager = getPackageManager();
            boolean noRadioDetected = !(packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY) && (packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_GSM) || packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_CDMA)));
            // show dialog if something is not supported
            if (noRadioDetected) {
                Timber.d("displayNotCompatibleDialog(): Not compatible because of radio: %s, phone type: %s", noRadioDetected, telephonyManager.getPhoneType());
                //use custom layout to show "don't show this again" checkbox
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
                LayoutInflater inflater = LayoutInflater.from(this);
                View dialogLayout = inflater.inflate(R.layout.dont_show_again_dialog, null);
                final CheckBox dontShowAgainCheckbox = (CheckBox) dialogLayout.findViewById(R.id.dont_show_again_dialog_checkbox);
                dialogBuilder.setView(dialogLayout);
                AlertDialog alertDialog = dialogBuilder.create();
                alertDialog.setCanceledOnTouchOutside(true);
                alertDialog.setCancelable(true);
                alertDialog.setTitle(R.string.main_dialog_not_compatible_title);
                StringBuilder stringBuilder = new StringBuilder(getString(R.string.main_dialog_not_compatible_begin));
                if (noRadioDetected) {
                    stringBuilder.append(getString(R.string.main_dialog_no_compatible_mobile_radio_message));
                }
                // text set this way to prevent checkbox from disappearing when text is too long
                TextView messageTextView = (TextView) dialogLayout.findViewById(R.id.dont_show_again_dialog_textview);
                messageTextView.setText(stringBuilder.toString());
                alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_ok), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        boolean dontShowAgainCheckboxChecked = dontShowAgainCheckbox.isChecked();
                        Timber.d("displayNotCompatibleDialog(): Don't show again checkbox checked = %s", dontShowAgainCheckboxChecked);
                        if (dontShowAgainCheckboxChecked) {
                            MyApplication.getPreferencesProvider().setShowCompatibilityWarning(false);
                        }
                    }
                });
                alertDialog.show();
            }
        }
        showNotCompatibleDialog = false;
    }
}
 
Example 18
/**
 * open camera
 *
 * @param fragment
 * @throws IOException
 */

public void requestTakePicture(final Fragment fragment) throws IOException {

    PackageManager packageManager = context.getPackageManager();
    if (!packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        Toast.makeText(context, context.getString(R.string.device_dosenot_camera_en), Toast.LENGTH_SHORT).show();
        return;
    }

    HelperPermission.getCameraPermission(context, new OnGetPermission() {
        @Override
        public void Allow() throws IOException {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                dispatchTakePictureIntent(fragment);
            } else {
                Uri outPath = getOutputMediaFileUri(MEDIA_TYPE_IMAGE, 0);

                if (outPath != null) {
                    imagePath = outPath.getPath();
                    imageUri = outPath;
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, outPath);

                    if (fragment != null) {
                        fragment.startActivityForResult(intent, request_code_TAKE_PICTURE);
                    } else {
                        ((Activity) context).startActivityForResult(intent, request_code_TAKE_PICTURE);
                    }

                    isInAttach = true;
                }
            }
        }

        @Override
        public void deny() {

        }
    });

}
 
Example 19
/**
 *      ADAPTER
 */

public boolean isThingsDevice(Context context) {
    final PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature("android.hardware.type.embedded");
}
 
Example 20
Source Project: AlbumCameraRecorder   File: MediaStoreCompat.java    License: MIT License 2 votes vote down vote up
/**
 * 检查设备是否具有相机特性。
 *
 * @param context 检查相机特征的上下文。
 * @return 如果设备具有相机特性,则为真。否则为假。
 */
public static boolean hasCameraFeature(Context context) {
    PackageManager pm = context.getApplicationContext().getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}