Example usage for android.nfc NfcManager getDefaultAdapter

List of usage examples for android.nfc NfcManager getDefaultAdapter

Introduction

In this page you can find the example usage for android.nfc NfcManager getDefaultAdapter.

Prototype

public NfcAdapter getDefaultAdapter() 

Source Link

Document

Get the default NFC Adapter for this device.

Usage

From source file:Main.java

/**
 * Return the NfcAdapter object or null. All devices without a hardware NFC module
 * will return null. All devices with Android 2.3.0 (API 9) or lower will return null,
 * caused by missing API support. //from w  w  w  . j av a 2  s .  c  o  m
 * 
 * @param context Android Context
 * @return NfcAdapter object or null
 */
@SuppressLint("NewApi")
public static NfcAdapter getNfcAdapter(Context context) {
    if (Build.VERSION.SDK_INT < MIN_SDK_INT_FOR_NFC) {
        return null;
    } else {
        final NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
        final NfcAdapter adapter = manager.getDefaultAdapter();
        return adapter;
    }
}

From source file:com.coinblesk.client.utils.UIUtils.java

private static boolean hasNFC(Context context) {
    NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    return adapter != null;
}

From source file:com.coinblesk.client.utils.UIUtils.java

private static boolean isNFCEnabled(Context context) {
    NfcManager manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    return adapter != null && adapter.isEnabled();
}

From source file:com.macleod2486.androidswissknife.views.NFC.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.nfc, container, false);

    tool = new NFCTool(getActivity());

    writeNFC = (Button) view.findViewById(R.id.writeNFC);
    writeNFC.setOnClickListener(tool);//from  ww w  .  j a  va 2s  .c o m

    clearText = (Button) view.findViewById(R.id.clearText);
    clearText.setOnClickListener(tool);

    Log.i("NFCTool", "Scanning");

    NfcManager manager;
    NfcAdapter adapter;

    manager = (NfcManager) getActivity().getSystemService(getActivity().getApplicationContext().NFC_SERVICE);
    adapter = manager.getDefaultAdapter();

    NFCCallback callback = new NFCCallback(getActivity());

    Bundle opts = new Bundle();
    opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);

    adapter.enableReaderMode(getActivity(), callback, NfcAdapter.FLAG_READER_NFC_A, opts);

    Toast.makeText(this.getActivity(), "Please scan tag with device.", Toast.LENGTH_LONG).show();

    return view;
}

From source file:com.amazonaws.devicefarm.android.referenceapp.Fragments.FixturesFragment.java

/**
 * Updates the NFC Status/*from  w  ww  .  j  a v a 2  s  .c o  m*/
 */
@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()));
}

From source file:com.robopupu.component.AppManagerImpl.java

@Override
public boolean hasNfc() {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
        final NfcManager manager = D.get(NfcManager.class);
        final NfcAdapter adapter = manager.getDefaultAdapter();
        return (adapter != null && adapter.isEnabled());
    }//from  www.  j ava 2s.c o m
    return false;
}

From source file:mintcoin.wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = activity;
    this.application = (WalletApplication) activity.getApplication();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:biz.wiz.android.wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = activity;
    this.application = (WalletApplication) activity.getApplication();
    this.wallet = application.getWallet();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:com.matthewmitchell.peercoin_android_wallet.ui.WalletAddressFragment.java

@Override
public void onAttach(final Activity activity) {
    super.onAttach(activity);

    this.activity = (WalletActivity) activity;
    this.application = (WalletApplication) activity.getApplication();
    this.loaderManager = getLoaderManager();
    final NfcManager nfcManager = (NfcManager) activity.getSystemService(Context.NFC_SERVICE);
    this.nfcAdapter = nfcManager.getDefaultAdapter();
}

From source file:org.openhab.habdroid.ui.OpenHABWriteTagActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Util.setActivityTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.openhabwritetag);

    Toolbar toolbar = findViewById(R.id.openhab_toolbar);
    setSupportActionBar(toolbar);//  ww w  . j a v  a2s . co m
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    NfcManager manager = (NfcManager) getSystemService(Context.NFC_SERVICE);
    mNfcAdapter = manager.getDefaultAdapter();

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().add(R.id.writenfc_container, getFragment()).commit();
    }

    setResult(RESULT_OK);

    mSitemapPage = getIntent().getStringExtra("sitemapPage");
    Log.d(TAG, "Got sitemapPage = " + mSitemapPage);
    mItem = getIntent().getStringExtra("item");
    Log.d(TAG, "Got item = " + mItem);
    mCommand = getIntent().getStringExtra("command");
    Log.d(TAG, "Got command = " + mCommand);
}