android.nfc.NfcManager Java Examples

The following examples show how to use android.nfc.NfcManager. 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: RNHceModule.java    From react-native-nfc-hce with Apache License 2.0 6 votes vote down vote up
private WritableMap supportNFC() {
    NfcManager manager = (NfcManager) this.reactContext.getSystemService(this.reactContext.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    WritableMap map = Arguments.createMap();
    if (adapter != null) {
        map.putBoolean("support", true);
        if (adapter.isEnabled()) {
            map.putBoolean("enabled", true);
        } else {
            map.putBoolean("enabled", false);
        }
    } else {
        map.putBoolean("support", false);
        map.putBoolean("enabled", false);
    }

    return map;
}
 
Example #2
Source File: NetWorkInfo.java    From MobileInfo with Apache License 2.0 6 votes vote down vote up
private static boolean hasNfc(Context context) {
    boolean bRet = false;
    if (context == null) {
        return false;
    }
    NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    if (manager == null) {
        return false;
    }
    NfcAdapter adapter = manager.getDefaultAdapter();
    if (adapter != null && adapter.isEnabled()) {
        // adapter存在,能启用
        bRet = true;
    }
    return bRet;
}
 
Example #3
Source File: BlogViewer.java    From Wrox-ProfessionalAndroid-4E with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  // Get the NFC Adapter.
  NfcManager nfcManager = (NfcManager)getSystemService(Context.NFC_SERVICE);
  mNFCAdapter = nfcManager.getDefaultAdapter();

  // Create the Pending Intent.
  int flags = 0;
  Intent nfcIntent = new Intent(this, getClass());
  nfcIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
  mNFCPendingIntent =
    PendingIntent.getActivity(this, NFC_REQUEST_CODE, nfcIntent, flags);

  // Create an Intent Filter limited to the URI or MIME type to
  // intercept TAG scans from.
  IntentFilter tagIntentFilter =
    new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
  tagIntentFilter.addDataScheme("http");
  tagIntentFilter.addDataAuthority("blog.radioactiveyak.com", null);
  mIntentFiltersArray = new IntentFilter[] { tagIntentFilter };

  // Create an array of technologies to handle.
  mTechListsArray = new String[][] {
    new String[] {
      NfcF.class.getName()
    }
  };

  // Process the Intent used to start the Activity/
  String action = getIntent().getAction();
  if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))
    processIntent(getIntent());
}
 
Example #4
Source File: MainActivity.java    From OpenLibre with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);

    mRealmRawData = Realm.getInstance(realmConfigRawData);
    mRealmProcessedData = Realm.getInstance(realmConfigProcessedData);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Create the adapter that will return a fragment for each of the
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), getApplicationContext());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.view_pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(mViewPager);

    mNfcAdapter = ((NfcManager) this.getSystemService(Context.NFC_SERVICE)).getDefaultAdapter();
    if (mNfcAdapter != null) {
        Log.d(LOG_ID, "Got NFC adapter");
        if (!mNfcAdapter.isEnabled()) {
            Toast.makeText(this, getResources().getString(R.string.error_nfc_disabled), Toast.LENGTH_LONG).show();
        }
    } else {
        Log.e(LOG_ID,"No NFC adapter found!");
        Toast.makeText(this, getResources().getString(R.string.error_nfc_device_not_supported), Toast.LENGTH_LONG).show();
    }
}
 
Example #5
Source File: DeviceStatusUtil.java    From under-the-hood with Apache License 2.0 5 votes vote down vote up
/**
 * Current NFC hardware state. Needs correct permission to work.
 *
 * @param context
 * @return state
 */
//@RequiresPermission(Manifest.permission.NFC)
public static Status getNfcState(Context context) {
    NfcManager nfcManager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = nfcManager.getDefaultAdapter();
    if (adapter == null) {
        return Status.UNSUPPORTED;
    } else if (ContextCompat.checkSelfPermission(context, Manifest.permission.NFC) != PackageManager.PERMISSION_GRANTED) {
        return Status.NEEDS_PERMISSION;
    } else if (adapter.isEnabled()) {
        return Status.ENABLED;
    } else {
        return Status.DISABLED;
    }
}
 
Example #6
Source File: FixturesFragment.java    From aws-device-farm-sample-app-for-android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the NFC Status
 */
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
private void updateNFCStatusDisplay() {
    final NfcManager nfcManager = (NfcManager) getActivity().getSystemService(Context.NFC_SERVICE);
    final NfcAdapter adapter = nfcManager.getDefaultAdapter();
    nfc.setText(Boolean.toString(adapter != null && adapter.isEnabled()));
}
 
Example #7
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #8
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #9
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #10
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #11
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #12
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #13
Source File: ContextImpl.java    From AndroidComponentPlugin with Apache License 2.0 4 votes vote down vote up
public Object createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #14
Source File: SystemServiceRegistry.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public NfcManager createService(ContextImpl ctx) {
    return new NfcManager(ctx);
}
 
Example #15
Source File: ServiceUtil.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(10)
public static NfcManager getNfcManager() {
    return (NfcManager) getSystemService(Context.NFC_SERVICE);
}
 
Example #16
Source File: NfcIconData.java    From Status with Apache License 2.0 4 votes vote down vote up
public NfcIconData(Context context) {
    super(context);
    manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
}