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

The following examples show how to use android.content.pm.PackageManager#hasSystemFeature() . 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 check out the related API usage on the sidebar.
Example 1
Source File: LocationUtils.java    From WifiUtils with 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 File: LocationFineTest.java    From AndPermission with 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
Source File: SubsonicActivity.java    From Audinaut with GNU General Public License v3.0 6 votes vote down vote up
@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 File: BleManager.java    From SweetBlue with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 5
Source File: CameraUtils.java    From Lassi-Android with 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 6
Source File: SensorStepServiceManager.java    From StepSensor with 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 7
Source File: BarometerNetworkActivity.java    From PressureNet with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 8
Source File: Helper.java    From FairEmail with 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 9
Source File: OpenNoteCameraView.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
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 10
Source File: DeviceStorageMonitorService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: IntentUtils.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
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 12
Source File: StepSensor.java    From react-native-google-fit with 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 13
Source File: SystemUtil.java    From Augendiagnose with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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 14
Source File: EmuDetector.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private boolean isSupportTelePhony() {
    PackageManager packageManager = mContext.getPackageManager();
    return packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
}
 
Example 15
Source File: Helper.java    From FairEmail with 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 16
Source File: MainActivity.java    From TowerCollector with Mozilla Public License 2.0 4 votes vote down vote up
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 17
Source File: DoubleMeasureFixUtil.java    From litho with 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 18
Source File: AttachFile.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * 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
Source File: DevicesActivity.java    From bridgefy-android-samples with MIT License 4 votes vote down vote up
/**
 *      ADAPTER
 */

public boolean isThingsDevice(Context context) {
    final PackageManager pm = context.getPackageManager();
    return pm.hasSystemFeature("android.hardware.type.embedded");
}
 
Example 20
Source File: MediaStoreCompat.java    From AlbumCameraRecorder with 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);
}