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:org.ndeftools.NfcDetectorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");

    // Check for available NFC Adapter
    PackageManager pm = getPackageManager();
    if (pm != null && !pm.hasSystemFeature(PackageManager.FEATURE_NFC)) {
        Log.d(TAG, "NFC feature not found");

        onNfcFeatureNotFound();/*from w  ww  . j  a  va  2 s. c o m*/
    } else {
        Log.d(TAG, "NFC feature found");

        onNfcFeatureFound();
    }
}

From source file:com.android.idearse.Result.java

public boolean isCameraAvailable() {
    PackageManager pm = getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_CAMERA);
}

From source file:com.platform.middlewares.plugins.CameraPlugin.java

@Override
public boolean handle(String target, final Request baseRequest, final HttpServletRequest request,
        final HttpServletResponse response) {

    // GET /_camera/take_picture
    ///*from w  ww  . j a  v a 2 s.  c  om*/
    // Optionally pass ?overlay=<id> (see overlay ids below) to show an overlay
    // in picture taking mode
    //
    // Status codes:
    //   - 200: Successful image capture
    //   - 204: User canceled image picker
    //   - 404: Camera is not available on this device
    //   - 423: Multiple concurrent take_picture requests. Only one take_picture request may be in flight at once.
    //

    if (target.startsWith("/_camera/take_picture")) {
        Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod());
        final MainActivity app = MainActivity.app;
        if (app == null) {
            Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod());

            return BRHTTPHelper.handleError(500, "context is null", baseRequest, response);
        }

        if (globalBaseRequest != null) {
            Log.e(TAG, "handle: already taking a picture: " + target + " " + baseRequest.getMethod());

            return BRHTTPHelper.handleError(423, null, baseRequest, response);
        }

        PackageManager pm = app.getPackageManager();

        if (!pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            Log.e(TAG, "handle: no camera available: ");
            return BRHTTPHelper.handleError(402, null, baseRequest, response);
        }
        if (ContextCompat.checkSelfPermission(app,
                Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
            // Should we show an explanation?
            if (ActivityCompat.shouldShowRequestPermissionRationale(app, Manifest.permission.CAMERA)) {
                Log.e(TAG, "handle: no camera access, showing instructions");
                ((BreadWalletApp) app.getApplication()).showCustomToast(app,
                        app.getString(R.string.allow_camera_access), MainActivity.screenParametersPoint.y / 2,
                        Toast.LENGTH_LONG, 0);
            } else {
                // No explanation needed, we can request the permission.
                ActivityCompat.requestPermissions(app, new String[] { Manifest.permission.CAMERA },
                        BRConstants.CAMERA_REQUEST_GLIDERA_ID);
            }
        } else {
            Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            if (takePictureIntent.resolveActivity(app.getPackageManager()) != null) {
                app.startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
            }

            continuation = ContinuationSupport.getContinuation(request);
            continuation.suspend(response);
            globalBaseRequest = baseRequest;
        }

        return true;
    } else if (target.startsWith("/_camera/picture/")) {
        Log.i(TAG, "handling: " + target + " " + baseRequest.getMethod());
        final MainActivity app = MainActivity.app;
        if (app == null) {
            Log.e(TAG, "handle: context is null: " + target + " " + baseRequest.getMethod());
            return BRHTTPHelper.handleError(500, "context is null", baseRequest, response);
        }
        String id = target.replace("/_camera/picture/", "");
        byte[] pictureBytes = readPictureForId(app, id);
        if (pictureBytes == null) {
            Log.e(TAG, "handle: WARNING pictureBytes is null: " + target + " " + baseRequest.getMethod());
            return BRHTTPHelper.handleError(500, "pictureBytes is null", baseRequest, response);
        }
        byte[] imgBytes = pictureBytes;
        String b64opt = request.getParameter("base64");
        String contentType = "image/jpeg";
        if (b64opt != null && !b64opt.isEmpty()) {
            contentType = "text/plain";
            String b64 = "data:image/jpeg;base64," + Base64.encodeToString(pictureBytes, Base64.NO_WRAP);
            try {
                imgBytes = b64.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
                return BRHTTPHelper.handleError(500, null, baseRequest, response);
            }
        }
        return BRHTTPHelper.handleSuccess(200, null, baseRequest, response, contentType);
    } else
        return false;
}

From source file:com.feathercoin.wallet.feathercoin.ui.SendingAddressesFragment.java

@SuppressLint("InlinedApi")
@Override/*from   w w w.ja  v a 2s. c  o  m*/
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.sending_addresses_fragment_options, menu);

    final PackageManager pm = activity.getPackageManager();
    menu.findItem(R.id.sending_addresses_options_scan)
            .setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
                    || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.android.managedprovisioning.ProfileOwnerPreProvisioningActivity.java

private boolean systemHasManagedProfileFeature() {
    PackageManager pm = getPackageManager();
    return pm.hasSystemFeature(PackageManager.FEATURE_MANAGED_USERS);
}

From source file:cc.mintcoin.wallet.ui.SendingAddressesFragment.java

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

    final PackageManager pm = activity.getPackageManager();
    menu.findItem(R.id.sending_addresses_options_scan)
            .setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
                    || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.framgia.android.emulator.EmulatorDetector.java

private boolean isSupportTelePhony() {
    PackageManager packageManager = mContext.getPackageManager();
    boolean isSupport = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    log("Supported TelePhony: " + isSupport);
    return isSupport;
}

From source file:com.example.android.wearable.speaker.MainActivity.java

/**
 * Determines if the wear device has a built-in speaker and if it is supported. Speaker, even if
 * physically present, is only supported in Android M+ on a wear device..
 *//*from  w w  w  .ja v a  2s  .co  m*/
public final boolean speakerIsSupported() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        PackageManager packageManager = getPackageManager();
        // The results from AudioManager.getDevices can't be trusted unless the device
        // advertises FEATURE_AUDIO_OUTPUT.
        if (!packageManager.hasSystemFeature(PackageManager.FEATURE_AUDIO_OUTPUT)) {
            return false;
        }
        AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
        for (AudioDeviceInfo device : devices) {
            if (device.getType() == AudioDeviceInfo.TYPE_BUILTIN_SPEAKER) {
                return true;
            }
        }
    }
    return false;
}

From source file:com.cannabiscoin.wallet.ui.SendingAddressesFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    //Fixed menu item doubling on rotate in address screen - langerhans (https://github.com/langerhans/dogecoin-wallet-new)
    if (menu.findItem(R.id.sending_addresses_options_paste) == null
            && menu.findItem(R.id.sending_addresses_options_scan) == null) {
        inflater.inflate(R.menu.sending_addresses_fragment_options, menu);

        final PackageManager pm = activity.getPackageManager();
        menu.findItem(R.id.sending_addresses_options_scan)
                .setVisible(pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)
                        || pm.hasSystemFeature(PackageManager.FEATURE_CAMERA_FRONT));

        super.onCreateOptionsMenu(menu, inflater);
    }//from w  w  w. ja v  a  2s.c o  m
}

From source file:au.com.spinninghalf.connectingtothenetwork.ActionBarTabsPager.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //getWindow().setWindowAnimations(android.R.anim.slide_in_left);
    //overridePendingTransition(R.anim.fadein, R.anim.fadeout);

    shapp = SpinningHalfApplication.getInstance();

    PackageManager pm = getPackageManager();

    //determine whether the device has telephony capabilities i.e. can make a phone call
    boolean telephonySupported = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    // set the result to the application variable 'hasDeviceTelephonyCapabilities'.
    shapp.setTelephonyCapability(telephonySupported);

    mViewPager = new ViewPager(this);
    mViewPager.setId(R.id.pager);/*from www .  ja  v a 2  s.c  om*/
    setContentView(mViewPager);

    final ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);

    /*
    BitmapDrawable bg = (BitmapDrawable)getResources().getDrawable(R.drawable.ic_action_spinning_half_tab_style);
    bg.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    getSupportActionBar().setBackgroundDrawable(bg);
    */

    /*
    BitmapDrawable bgSplit = (BitmapDrawable)getResources().getDrawable(R.drawable.ic_action_spinning_half_tab_style);
    bgSplit.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    getSupportActionBar().setSplitBackgroundDrawable(bgSplit);
    */

    mTabsAdapter = new TabsAdapter(this, mViewPager);

    mTabsAdapter.addTab(bar.newTab().setText("News"), NewsFragmentOne.class, null, "NEWS_TAG");
    mTabsAdapter.addTab(bar.newTab().setText("Rehearsals"), RehearsalsFragmentOne.class, null,
            "REHEARSALS_TAG");
    mTabsAdapter.addTab(bar.newTab().setText("Gig Guide"), GigListFragment.class, null, "GIG_LIST_TAG");
    mTabsAdapter.addTab(bar.newTab().setText("Management"), ManagementFragmentOne.class, null,
            "MANAGEMENT_TAG");
    mTabsAdapter.addTab(bar.newTab().setText("Services"), ServicesFragmentOne.class, null, "SERVICES_TAG");
    mTabsAdapter.addTab(bar.newTab().setText("Contact"), ContactFragmentOne.class, null, "CONTACT_TAG");

    if (savedInstanceState != null) {
        bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
    }
}