Example usage for android.content.pm PackageManager FEATURE_NFC

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

Introduction

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

Prototype

String FEATURE_NFC

To view the source code for android.content.pm PackageManager FEATURE_NFC.

Click Source Link

Document

Feature for #getSystemAvailableFeatures and #hasSystemFeature : The device can communicate using Near-Field Communications (NFC).

Usage

From source file:Main.java

public static boolean hasNfc(Context context) {
    return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
}

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  va2 s . c  o  m*/
    } else {
        Log.d(TAG, "NFC feature found");

        onNfcFeatureFound();
    }
}

From source file:org.ndeftools.util.activity.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.hasSystemFeature(PackageManager.FEATURE_NFC)) {
        Log.d(TAG, "NFC feature not found");

        onNfcFeatureNotFound();/* w  w w . j ava  2 s.com*/
    } else {
        Log.d(TAG, "NFC feature found");

        onNfcFeatureFound();
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    try {/*ww  w. j a v  a2  s  .com*/
        if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
                && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            inflater.inflate(R.menu.view_device, menu);
        }
    } catch (Exception e) {
        e.printStackTrace();
        BugSenseHandler.sendExceptionMessage("ViewZenossDeviceFragment", "onCreateOptionsMenu", e);
    }
}

From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    //Log.e("ViewZenossDeviceFragment", Integer.toString(item.getItemId()) + " / " + Integer.toString(R.id.writenfc));

    switch (item.getItemId()) {
    case R.id.writenfc: {
        try {//from  w  w  w .j  a  v a2 s .  c o  m
            if (getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)
                    && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                Intent NFCIntent = new Intent(getActivity(), WriteNFCActivity.class);
                try {
                    NFCIntent.putExtra(WriteNFCActivity.PAYLOAD_UID,
                            deviceJSON.getJSONObject("result").getJSONObject("data").getString("uid"));
                    this.startActivity(NFCIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(getActivity(), "Sorry there was error parsing the UID for this device",
                            Toast.LENGTH_SHORT).show();
                }
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            BugSenseHandler.sendExceptionMessage("ViewZenossDeviceFragment", "onOptionsItemSelected", e);
            return false;
        }
    }

    default:
        break;
    }

    return false;
}

From source file:com.android.settings.profiles.SetupTriggersFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_setup_triggers, container, false);

    mPager = (ViewPager) root.findViewById(R.id.view_pager);
    mAdapter = new TriggerPagerAdapter(getActivity(), getChildFragmentManager());

    Bundle profileArgs = new Bundle();
    profileArgs.putParcelable(ProfilesSettings.EXTRA_PROFILE, mProfile);

    final TriggerPagerAdapter.TriggerFragments[] fragments = TriggerPagerAdapter.TriggerFragments.values();

    for (final TriggerPagerAdapter.TriggerFragments fragment : fragments) {
        if (fragment.getFragmentClass() == NfcTriggerFragment.class) {
            if (!getActivity().getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
                // device doesn't have NFC
                continue;
            }//from   w ww  . j  ava  2  s.c  o  m
        }
        mAdapter.add(fragment.getFragmentClass(), profileArgs, fragment.getTitleRes());
    }

    mPager.setAdapter(mAdapter);

    PagerTabStrip tabs = (PagerTabStrip) root.findViewById(R.id.tabs);
    tabs.setTabIndicatorColorResource(R.color.theme_accent);

    if (mNewProfileMode) {
        Button nextButton = (Button) root.findViewById(R.id.next);
        nextButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle args = new Bundle();
                args.putParcelable(ProfilesSettings.EXTRA_PROFILE, mProfile);
                args.putBoolean(ProfilesSettings.EXTRA_NEW_PROFILE, mNewProfileMode);

                SubSettings pa = (SubSettings) getActivity();
                pa.startPreferencePanel(SetupActionsFragment.class.getCanonicalName(), args,
                        R.string.profile_profile_manage, null, SetupTriggersFragment.this,
                        REQUEST_SETUP_ACTIONS);
            }
        });

        // back button
        root.findViewById(R.id.back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finishFragment();
            }
        });
    } else {
        root.findViewById(R.id.bottom_buttons).setVisibility(View.GONE);
    }
    return root;
}

From source file:Main.java

/**
 * A single feature that can be requested by an application.
 * This corresponds to information collected from the AndroidManifest.xml's tag.
 * @param feature "FeatureInfo"//from  w ww. ja  v  a 2s  .c o m
 */
@SuppressWarnings("deprecation")
public static String getFeature(String feature) {
    if (TextUtils.isEmpty(feature)) {
        return UNKNOWN;
    }

    switch (feature) {
    case PackageManager.FEATURE_APP_WIDGETS://android.software.app_widgets
        return "FEATURE_APP_WIDGETS";
    case PackageManager.FEATURE_AUDIO_LOW_LATENCY://android.hardware.audio.low_latency
        return "FEATURE_AUDIO_LOW_LATENCY";
    case PackageManager.FEATURE_AUDIO_OUTPUT://android.hardware.audio.output
        return "FEATURE_AUDIO_OUTPUT";
    case PackageManager.FEATURE_AUDIO_PRO://android.hardware.audio.pro
        return "FEATURE_AUDIO_PRO";//API 23
    case PackageManager.FEATURE_AUTOMOTIVE://android.hardware.type.automotive
        return "FEATURE_AUTOMOTIVE";//API 23
    case PackageManager.FEATURE_BACKUP://android.software.backup
        return "FEATURE_BACKUP";
    case PackageManager.FEATURE_BLUETOOTH://android.hardware.bluetooth
        return "FEATURE_BLUETOOTH";
    case PackageManager.FEATURE_BLUETOOTH_LE://android.hardware.bluetooth_le
        return "FEATURE_BLUETOOTH_LE";
    case PackageManager.FEATURE_CAMERA://android.hardware.camera
        return "FEATURE_CAMERA";
    case PackageManager.FEATURE_CAMERA_ANY://android.hardware.camera.any
        return "FEATURE_CAMERA_ANY";
    case PackageManager.FEATURE_CAMERA_AUTOFOCUS://android.hardware.camera.autofocus
        return "FEATURE_CAMERA_AUTOFOCUS";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING://android.hardware.camera.capability.manual_post_processing
        return "FEATURE_CAMERA_CAPABILITY_MANUAL_POST_PROCESSING";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR://android.hardware.camera.capability.manual_sensor
        return "FEATURE_CAMERA_CAPABILITY_MANUAL_SENSOR";
    case PackageManager.FEATURE_CAMERA_CAPABILITY_RAW://android.hardware.camera.capability.raw
        return "FEATURE_CAMERA_CAPABILITY_RAW";
    case PackageManager.FEATURE_CAMERA_EXTERNAL://android.hardware.camera.external
        return "FEATURE_CAMERA_EXTERNAL";
    case PackageManager.FEATURE_CAMERA_FLASH://android.hardware.camera.flash
        return "FEATURE_CAMERA_FLASH";
    case PackageManager.FEATURE_CAMERA_FRONT://android.hardware.camera.front
        return "FEATURE_CAMERA_FRONT";
    case PackageManager.FEATURE_CAMERA_LEVEL_FULL://android.hardware.camera.level.full
        return "FEATURE_CAMERA_LEVEL_FULL";
    case PackageManager.FEATURE_CONNECTION_SERVICE://android.software.connectionservice
        return "FEATURE_CONNECTION_SERVICE";
    case PackageManager.FEATURE_CONSUMER_IR://android.hardware.consumerir
        return "FEATURE_CONSUMER_IR";
    case PackageManager.FEATURE_DEVICE_ADMIN://android.software.device_admin
        return "FEATURE_DEVICE_ADMIN";
    case PackageManager.FEATURE_FAKETOUCH://android.hardware.faketouch
        return "FEATURE_FAKETOUCH";
    case PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT://android.hardware.faketouch.multitouch.distinct
        return "FEATURE_FAKETOUCH_MULTITOUCH_DISTINCT";
    case PackageManager.FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND://android.hardware.faketouch.multitouch.jazzhand
        return "FEATURE_FAKETOUCH_MULTITOUCH_JAZZHAND";
    case PackageManager.FEATURE_FINGERPRINT://android.hardware.fingerprint
        return "FEATURE_FINGERPRINT";//API 23
    case PackageManager.FEATURE_GAMEPAD://android.hardware.gamepad
        return "FEATURE_GAMEPAD";
    case PackageManager.FEATURE_HIFI_SENSORS://android.hardware.sensor.hifi_sensors
        return "FEATURE_HIFI_SENSORS";//API 23
    case PackageManager.FEATURE_HOME_SCREEN://android.software.home_screen
        return "FEATURE_HOME_SCREEN";
    case PackageManager.FEATURE_INPUT_METHODS://android.software.input_methods
        return "FEATURE_INPUT_METHODS";
    case PackageManager.FEATURE_LEANBACK://android.software.leanback
        return "FEATURE_LEANBACK";
    case PackageManager.FEATURE_LIVE_TV://android.software.live_tv
        return "FEATURE_LIVE_TV";
    case PackageManager.FEATURE_LIVE_WALLPAPER://android.software.live_wallpaper
        return "FEATURE_LIVE_WALLPAPER";
    case PackageManager.FEATURE_LOCATION://android.hardware.location
        return "FEATURE_LOCATION";
    case PackageManager.FEATURE_LOCATION_GPS://android.hardware.location.gps
        return "FEATURE_LOCATION_GPS";
    case PackageManager.FEATURE_LOCATION_NETWORK://android.hardware.location.network
        return "FEATURE_LOCATION_NETWORK";
    case PackageManager.FEATURE_MANAGED_USERS://android.software.managed_users
        return "FEATURE_MANAGED_USERS";
    case PackageManager.FEATURE_MICROPHONE://android.hardware.microphone
        return "FEATURE_MICROPHONE";
    case PackageManager.FEATURE_MIDI://android.software.midi
        return "FEATURE_MIDI";//API 23
    case PackageManager.FEATURE_NFC://android.hardware.nfc
        return "FEATURE_NFC";
    case PackageManager.FEATURE_NFC_HOST_CARD_EMULATION://android.hardware.nfc.hce
        return "FEATURE_NFC_HOST_CARD_EMULATION";
    case PackageManager.FEATURE_OPENGLES_EXTENSION_PACK://android.hardware.opengles.aep
        return "FEATURE_OPENGLES_EXTENSION_PACK";
    case PackageManager.FEATURE_PRINTING://android.software.print
        return "FEATURE_PRINTING";
    case PackageManager.FEATURE_SCREEN_LANDSCAPE://android.hardware.screen.landscape
        return "FEATURE_SCREEN_LANDSCAPE";
    case PackageManager.FEATURE_SCREEN_PORTRAIT://android.hardware.screen.portrait
        return "FEATURE_SCREEN_PORTRAIT";
    case PackageManager.FEATURE_SECURELY_REMOVES_USERS://android.software.securely_removes_users
        return "FEATURE_SECURELY_REMOVES_USERS";
    case PackageManager.FEATURE_SENSOR_ACCELEROMETER://android.hardware.sensor.accelerometer
        return "FEATURE_SENSOR_ACCELEROMETER";
    case PackageManager.FEATURE_SENSOR_AMBIENT_TEMPERATURE://android.hardware.sensor.ambient_temperature
        return "FEATURE_SENSOR_AMBIENT_TEMPERATURE";
    case PackageManager.FEATURE_SENSOR_BAROMETER://android.hardware.sensor.barometer
        return "FEATURE_SENSOR_BAROMETER";
    case PackageManager.FEATURE_SENSOR_COMPASS://android.hardware.sensor.compass
        return "FEATURE_SENSOR_COMPASS";
    case PackageManager.FEATURE_SENSOR_GYROSCOPE://android.hardware.sensor.gyroscope
        return "FEATURE_SENSOR_GYROSCOPE";
    case PackageManager.FEATURE_SENSOR_HEART_RATE://android.hardware.sensor.heartrate
        return "FEATURE_SENSOR_HEART_RATE";
    case PackageManager.FEATURE_SENSOR_HEART_RATE_ECG://android.hardware.sensor.heartrate.ecg
        return "FEATURE_SENSOR_HEART_RATE_ECG";
    case PackageManager.FEATURE_SENSOR_LIGHT://android.hardware.sensor.light
        return "FEATURE_SENSOR_LIGHT";
    case PackageManager.FEATURE_SENSOR_PROXIMITY://android.hardware.sensor.proximity
        return "FEATURE_SENSOR_PROXIMITY";
    case PackageManager.FEATURE_SENSOR_RELATIVE_HUMIDITY://android.hardware.sensor.relative_humidity
        return "FEATURE_SENSOR_RELATIVE_HUMIDITY";
    case PackageManager.FEATURE_SENSOR_STEP_COUNTER://android.hardware.sensor.stepcounter
        return "FEATURE_SENSOR_STEP_COUNTER";
    case PackageManager.FEATURE_SENSOR_STEP_DETECTOR://android.hardware.sensor.stepdetector
        return "FEATURE_SENSOR_STEP_DETECTOR";
    case PackageManager.FEATURE_SIP://android.software.sip
        return "FEATURE_SIP";
    case PackageManager.FEATURE_SIP_VOIP://android.software.sip.voip
        return "FEATURE_SIP_VOIP";
    case PackageManager.FEATURE_TELEPHONY://android.hardware.telephony
        return "FEATURE_TELEPHONY";
    case PackageManager.FEATURE_TELEPHONY_CDMA://android.hardware.telephony.cdma
        return "FEATURE_TELEPHONY_CDMA";
    case PackageManager.FEATURE_TELEPHONY_GSM://android.hardware.telephony.gsm
        return "FEATURE_TELEPHONY_GSM";
    case PackageManager.FEATURE_TELEVISION://android.hardware.type.television
        return "FEATURE_TELEVISION";
    case PackageManager.FEATURE_TOUCHSCREEN://android.hardware.touchscreen
        return "FEATURE_TOUCHSCREEN";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH://android.hardware.touchscreen.multitouch
        return "FEATURE_TOUCHSCREEN_MULTITOUCH";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT://android.hardware.touchscreen.multitouch.distinct
        return "FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT";
    case PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND://android.hardware.touchscreen.multitouch.jazzhand
        return "FEATURE_TOUCHSCREEN_MULTITOUCH_JAZZHAND";
    case PackageManager.FEATURE_USB_ACCESSORY://android.hardware.usb.accessory
        return "FEATURE_USB_ACCESSORY";
    case PackageManager.FEATURE_USB_HOST://android.hardware.usb.host
        return "FEATURE_USB_HOST";
    case PackageManager.FEATURE_VERIFIED_BOOT://android.software.verified_boot
        return "FEATURE_VERIFIED_BOOT";
    case PackageManager.FEATURE_WATCH://android.hardware.type.watch
        return "FEATURE_WATCH";
    case PackageManager.FEATURE_WEBVIEW://android.software.webview
        return "FEATURE_WEBVIEW";
    case PackageManager.FEATURE_WIFI://android.hardware.wifi
        return "FEATURE_WIFI";
    case PackageManager.FEATURE_WIFI_DIRECT://android.hardware.wifi.direct
        return "FEATURE_WIFI_DIRECT";
    default:
        return UNKNOWN;
    }
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_network_active);

    // Create the adapter that will return a fragment for each of the three
    // primary sections of the app.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the action bar.
    final ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override/*from   w w  w .j  a  v  a2s  .  c  o  m*/
        public void onPageSelected(int position) {
            actionBar.setSelectedNavigationItem(position);
        }
    });

    // For each of the sections in the app, add a tab to the action bar.
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        actionBar
                .addTab(actionBar.newTab().setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this));
    }

    // Handle the change of the Wifi configuration
    wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    adhoc = new AdhocWifiManager(wifi);
    wifiapmanager = new WifiAPManager();
    registerReceiver(wifiReceiver, new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION));

    // Is NFC available on this device?
    nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);

    // only set up the NFC stuff if NFC is also available
    if (nfcAvailable) {
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        if (nfcAdapter.isEnabled()) {

            // Setting up a pending intent that is invoked when an NFC tag
            // is tapped on the back
            pendingIntent = PendingIntent.getActivity(this, 0,
                    new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

            nfcIntentFilter = new IntentFilter();
            nfcIntentFilter.addAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
            nfcIntentFilter.addAction(NfcAdapter.ACTION_TAG_DISCOVERED);
            intentFiltersArray = new IntentFilter[] { nfcIntentFilter };
        } else {
            nfcAvailable = false;
        }
    }
}

From source file:ch.bfh.instacircle.NetworkActiveActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.activity_network_active, menu);

    // only display the NFC action if NFC is available
    if (!this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC)) {
        menu.removeItem(R.id.write_nfc_tag);
    }//from w  w  w.java2  s . c o m
    return true;
}

From source file:org.protocoderrunner.apprunner.AppRunnerActivity.java

public void initializeNFC() {

    if (nfcInit == false) {
        PackageManager pm = getPackageManager();
        nfcSupported = pm.hasSystemFeature(PackageManager.FEATURE_NFC);

        if (nfcSupported == false) {
            return;
        }//from   ww  w  .  j av a  2s  .  co  m

        // cuando esta en foreground
        MLog.d(TAG, "Starting NFC");
        mAdapter = NfcAdapter.getDefaultAdapter(this);
        /*
         * mAdapter.setNdefPushMessageCallback(new
         * NfcAdapter.CreateNdefMessageCallback() {
         *
         * @Override public NdefMessage createNdefMessage(NfcEvent event) {
         * // TODO Auto-generated method stub return null; } }, this, null);
         */

        // Create mContext generic PendingIntent that will be deliver to this
        // activity.
        // The NFC stack will fill in the intent with the details of the
        // discovered tag before
        // delivering to this activity.
        mPendingIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

        // Setup an intent filter for all MIME based dispatches
        IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
        try {
            ndef.addDataType("*/*");
        } catch (IntentFilter.MalformedMimeTypeException e) {
            throw new RuntimeException("fail", e);
        }
        mFilters = new IntentFilter[] { ndef, };

        // Setup mContext tech list for all NfcF tags
        mTechLists = new String[][] { new String[] { NfcF.class.getName() } };
        nfcInit = true;
    }
}