Example usage for android.nfc NfcAdapter isEnabled

List of usage examples for android.nfc NfcAdapter isEnabled

Introduction

In this page you can find the example usage for android.nfc NfcAdapter isEnabled.

Prototype

public boolean isEnabled() 

Source Link

Document

Return true if this NFC Adapter has any features enabled.

Usage

From source file:Main.java

/**
 * Returns true is the NFC module is enables / switched on.
 * Attention! For devices with enabled NFC but with an Android version below API 10
 * false will be return. Caused by a missing NFC API below API 10.
 * /*from ww  w . j  a  v a2 s .  c  om*/
 * @param context Android Context
 * @return true if NFC is enabled
 * 
 * @see http://developer.android.com/reference/android/nfc/NfcAdapter.html#isEnabled%28%29
 * @see #getNfcAdapter(Context)
 */
@SuppressLint("NewApi")
public static boolean isNfcEnabled(Context context) {
    // all devices before API 10 are not NFC capable because of missing API support.
    // Therefore is nfc at all not enabled on these devices
    if (Build.VERSION.SDK_INT < MIN_SDK_INT_FOR_NFC) {
        return false;
    } else {
        final NfcAdapter adapter = getNfcAdapter(context);
        return (adapter != null && adapter.isEnabled());
    }
}

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.mario22gmail.license.nfc_project.FragmentEnableNFC.java

@Override
public void onResume() {
    NfcAdapter nfcAdapter;
    nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity());

    if ((nfcAdapter != null && nfcAdapter.isEnabled()) && isBackFromSettings) {
        Toast.makeText(this.getActivity(), "NFC pornit", Toast.LENGTH_LONG).show();
        getDialog().dismiss();/*w w w.j a  va  2s  .c  o  m*/
    }
    isBackFromSettings = true;
    Log.i("nfc_debug", "dialog is on resume");
    super.onResume();
}

From source file:com.mifirma.android.ConfigNfcDialog.java

@NonNull
@Override//from   www  .j av a2s  . c  o  m
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    return new AlertDialog.Builder(getActivity()).setMessage("Desea usar NFC para conexin con DNIe 3.0?")
            .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    MainActivity.setUseNfc(false);
                    dialog.dismiss();

                }
            }).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    MainActivity.setUseNfc(true);
                    dialog.dismiss();
                    NfcAdapter mAdapter = NfcAdapter.getDefaultAdapter(ConfigNfcDialog.this.getActivity());
                    if (mAdapter != null && !mAdapter.isEnabled()) {
                        new ActiveNfcDialog().show(
                                ConfigNfcDialog.this.getActivity().getSupportFragmentManager(),
                                "enableNfcDialog");
                    }
                }
            }).create();
}

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

/**
 * Updates the NFC Status//from   w ww . java2  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 w w  w  .  j av a  2  s . c  o m*/
    return false;
}

From source file:org.esupportail.nfctagdroid.NfcTacDroidActivity.java

public boolean checkHardware(NfcAdapter mAdapter) {
    if (mAdapter == null) {
        Toast.makeText(this, getString(R.string.msg_error_nfc), Toast.LENGTH_LONG).show();
        finish();/*from w  w w .  j a  v a2s  .c  o m*/
        return false;
    }

    if (!mAdapter.isEnabled()) {
        Toast.makeText(this, getString(R.string.msg_activ_nfc), Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_NFC_SETTINGS));
    }

    if (!isOnline()) {
        view.loadUrl("about:blank");
        Toast.makeText(this, getString(R.string.msg_activ_network), Toast.LENGTH_LONG).show();
        startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
    }
    return true;
}

From source file:net.basov.ticketinfo.UI.java

public void displayWelcomeByNFC(WebView wv) {
    Context c = wv.getContext();//www  .j a  v  a  2  s.  c  o m
    NfcAdapter adapter = NfcAdapter.getDefaultAdapter(c);
    if (adapter == null || !adapter.isEnabled()) {
        setWelcome("w_msg", "<font color=\"darkred\">" + c.getString(R.string.welcome_without_nfc) + "<font>");
    } else {
        setWelcome("w_msg", "<font color=\"darkgreen\">" + c.getString(R.string.welcome_with_nfc) + "<font>");
    }
    displayWelcomeScreen(wv);
}

From source file:com.evandroid.musica.fragment.LyricsViewFragment.java

@TargetApi(16)
private void beamLyrics(final Lyrics lyrics, Activity activity) {
    NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity);
    if (nfcAdapter != null && nfcAdapter.isEnabled()) {
        if (lyrics.getText() != null) {
            nfcAdapter.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
                @Override/*from  w  w w. j a v a  2s  . c  om*/
                public NdefMessage createNdefMessage(NfcEvent event) {
                    try {
                        byte[] payload = lyrics.toBytes(); // whatever data you want to send
                        NdefRecord record = new NdefRecord(NdefRecord.TNF_MIME_MEDIA,
                                "application/lyrics".getBytes(), new byte[0], payload);
                        return new NdefMessage(new NdefRecord[] { record, // your data
                                NdefRecord.createApplicationRecord("com.geecko.QuickLyric"), // the "application record"
                        });
                    } catch (IOException e) {
                        return null;
                    }
                }
            }, activity);
        }
    }
}

From source file:org.croudtrip.fragments.join.JoinDrivingFragment.java

private void switchToNfcIfAvailable() {
    NfcManager manager = (NfcManager) getActivity().getSystemService(Context.NFC_SERVICE);
    NfcAdapter adapter = manager.getDefaultAdapter();
    if (adapter != null && adapter.isEnabled()) {
        // nfc exists and is enabled.
        ivNfcIcon.setVisibility(View.VISIBLE);
        tvNfcExplanation.setVisibility(View.VISIBLE);
        btnReachedDestination.setVisibility(View.GONE);
    }/*from w  ww .  j a v a2s  .  c  om*/
}