List of usage examples for android.nfc NfcAdapter getDefaultAdapter
public static NfcAdapter getDefaultAdapter(Context context)
From source file:Main.java
/** * Creates a new NfcAdapter instance. */ public static NfcAdapter newNfcAdapter(Context context) { return NfcAdapter.getDefaultAdapter(context); }
From source file:Main.java
@TargetApi(14) private static NfcAdapter getAdapter(Context context) { if (Build.VERSION.SDK_INT < 14) return null; return NfcAdapter.getDefaultAdapter(context.getApplicationContext()); }
From source file:Main.java
/** * Gets the default NFC adapter.//from ww w. j av a 2 s . c o m * * @param context the {@link Context}. * @return the NFC adapter; or null if the device does not support NFC. */ private static NfcAdapter getNfcAdapter(Context context) { NfcAdapter nfcAdapter = null; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { nfcAdapter = NfcAdapter.getDefaultAdapter(context.getApplicationContext()); } return nfcAdapter; }
From source file:com.example.schoo.licenseverifer.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); //etSupportActionBar(toolbar); //mTextView = (TextView) findViewById(R.id.first_name_label); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); // mTextView.setText("NFC is disabled."); if (mNfcAdapter == null) { // Stop here, we definitely need NFC Toast.makeText(this, "This device doesn't support NFC.", Toast.LENGTH_LONG).show(); finish();// www .j ava 2s . co m return; } if (!mNfcAdapter.isEnabled()) { // mTextView.setText("NFC is disabled."); } else { // mTextView.setText(R.string.explanation); //mTextView.setText("NFC is enabled"); } handleIntent(getIntent()); initFields(); signupButton = (Button) findViewById(R.id.signup); signupButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { initFields(); } }); }
From source file:com.mario22gmail.license.nfc_project.FragmentEnableNFC.java
@Override public void onResume() { NfcAdapter nfcAdapter;/*from ww w. j a va2 s .c o m*/ nfcAdapter = NfcAdapter.getDefaultAdapter(getActivity()); if ((nfcAdapter != null && nfcAdapter.isEnabled()) && isBackFromSettings) { Toast.makeText(this.getActivity(), "NFC pornit", Toast.LENGTH_LONG).show(); getDialog().dismiss(); } isBackFromSettings = true; Log.i("nfc_debug", "dialog is on resume"); super.onResume(); }
From source file:ykim81.cs.brown.ykim81.cardreader.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (NfcAdapter.getDefaultAdapter(this) == null) { //Handle some NFC initialization here Toast.makeText(this, "NFC not available on this device", Toast.LENGTH_LONG).show(); }//from w ww . j av a2 s. com if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); CardReaderFragment fragment = new CardReaderFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } }
From source file:ykim81.cs.brown.ykim81.cardemulation.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (NfcAdapter.getDefaultAdapter(this) == null) { //Handle some NFC initialization here Toast.makeText(this, "NFC not available on this device", Toast.LENGTH_LONG).show(); }//from w w w . j a v a 2s . c o m if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); CardEmulationFragment fragment = new CardEmulationFragment(); transaction.replace(R.id.sample_content_fragment, fragment); transaction.commit(); } }
From source file:com.villetainio.travelcardreminder.activities.MainActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter == null) { Toast.makeText(this, R.string.error_message_no_nfc_on_device, Toast.LENGTH_LONG).show(); finish();/* w ww. j a va 2 s. c om*/ } pagerAdapter = new TravelCardPagerAdapter(getSupportFragmentManager()); pager = (VerticalViewPager) findViewById(R.id.pager); pager.setAdapter(pagerAdapter); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.TabListener tabListener = new ActionBar.TabListener() { @Override public void onTabSelected(ActionBar.Tab tab, android.app.FragmentTransaction ft) { pager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) { // Unselect } @Override public void onTabReselected(ActionBar.Tab tab, android.app.FragmentTransaction ft) { // Reselect } }; actionBar.addTab(actionBar.newTab().setText("Status").setTabListener(tabListener)); actionBar.addTab(actionBar.newTab().setText("Settings").setTabListener(tabListener)); } }
From source file:com.commonsware.android.webbeam.WebBeamActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); beamFragment = (BeamFragment) getSupportFragmentManager().findFragmentById(android.R.id.content); if (beamFragment == null) { beamFragment = new BeamFragment(); getSupportFragmentManager().beginTransaction().add(android.R.id.content, beamFragment).commit(); }//www . j a v a2 s . co m adapter = NfcAdapter.getDefaultAdapter(this); findViewById(android.R.id.content).post(new Runnable() { public void run() { handleIntent(getIntent()); } }); }
From source file:com.mifirma.android.ConfigNfcDialog.java
@NonNull @Override//from w ww.j a v a 2s. 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(); }