List of usage examples for android.nfc NfcAdapter getDefaultAdapter
public static NfcAdapter getDefaultAdapter(Context context)
From source file:org.ndeftools.NfcDetectorActivity.java
/** * /*from ww w.j a v a 2s . c om*/ * Initialize Nfc fields * */ protected void initializeNfc() { nfcAdapter = NfcAdapter.getDefaultAdapter(this); nfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED); writeTagFilters = new IntentFilter[] { ndefDetected, tagDetected, techDetected }; }
From source file:com.battlelancer.seriesguide.ui.OverviewActivity.java
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override/*www. ja va 2s. c o m*/ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_overview); setupActionBar(); setupNavDrawer(); mShowId = getIntent().getIntExtra(OverviewFragment.InitBundle.SHOW_TVDBID, -1); if (mShowId == -1) { finish(); return; } setupViews(savedInstanceState); // Support beaming shows via Android Beam if (AndroidUtils.isICSOrHigher()) { mNfcAdapter = NfcAdapter.getDefaultAdapter(this); if (mNfcAdapter != null) { mNfcAdapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { final Series show = DBUtils.getShow(OverviewActivity.this, mShowId); // send id, also title and overview (both can be empty) return new NdefMessage(new NdefRecord[] { createMimeRecord("application/com.battlelancer.seriesguide.beam", String.valueOf(mShowId).getBytes()), createMimeRecord("application/com.battlelancer.seriesguide.beam", show.getTitle().getBytes()), createMimeRecord("application/com.battlelancer.seriesguide.beam", show.getOverview().getBytes()) }); } /** * Creates a custom MIME type encapsulated in an NDEF record */ public NdefRecord createMimeRecord(String mimeType, byte[] payload) { byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII")); return new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload); } }, this); } } updateShowDelayed(mShowId); }
From source file:com.codebutler.farebot.activities.MainActivity.java
@Override protected void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.activity_main); ActionBar actionBar = getActionBar(); actionBar.setHomeButtonEnabled(false); mDataCache = new HashMap<String, TransitIdentity>(); registerForContextMenu(getListView()); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); Intent intent = new Intent(this, ReadingTagActivity.class); intent.addFlags(/* ww w.ja va 2s . c o m*/ Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY); mPendingIntent = PendingIntent.getActivity(this, 0, intent, 0); mTechLists = new String[][] { new String[] { IsoDep.class.getName() }, new String[] { MifareClassic.class.getName() }, new String[] { MifareUltralight.class.getName() }, new String[] { NfcF.class.getName() } }; setListAdapter(new CardsAdapter()); getLoaderManager().initLoader(0, null, this); }
From source file:com.example.android.beamlargefiles.BeamLargeFilesFragment.java
/** * Standard lifecycle event. Registers a callback for large-file transfer, by calling * NfcAdapter.setBeamPushUrisCallback(). * * Note: Like sending NDEF messages over standard Android Beam, there is also a non-callback * API available. See: NfcAdapter.setBeamPushUris(). * * @param savedInstanceState Saved instance state. *//*from w w w .ja va 2s . c om*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setHasOptionsMenu(true); Activity a = getActivity(); // Setup Beam to transfer a large file. Note the call to setBeamPushUrisCallback(). // BEGIN_INCLUDE(setBeamPushUrisCallback) NfcAdapter nfc = NfcAdapter.getDefaultAdapter(a); if (nfc != null) { Log.w(TAG, "NFC available. Setting Beam Push URI callback"); nfc.setBeamPushUrisCallback(this, a); } else { Log.w(TAG, "NFC is not available"); } // END_INCLUDE(setBeamPushUrisCallback) }
From source file:com.example.android.cardreader.CardReaderFragment.java
private void disableReaderMode() { Log.i(TAG, "Disabling reader mode"); Activity activity = getActivity();// w ww. jav a 2 s . c o m NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity); if (nfc != null) { nfc.disableReaderMode(activity); } }
From source file:com.android.cts.verifier.managedprovisioning.NfcTestActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.byod_nfc_test_activity); mAdminReceiverComponent = new ComponentName(this, DeviceAdminTestReceiver.class.getName()); mDevicePolicyManager = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); mUserMangaer = (UserManager) getSystemService(Context.USER_SERVICE); mDisallowByPolicy = getIntent().getBooleanExtra(EXTRA_DISALLOW_BY_POLICY, false); if (mDisallowByPolicy) { mDevicePolicyManager.addUserRestriction(mAdminReceiverComponent, UserManager.DISALLOW_OUTGOING_BEAM); }//from w w w . jav a 2s .com final Uri uri = createUriForImage(SAMPLE_IMAGE_FILENAME, SAMPLE_IMAGE_CONTENT); Uri[] uris = new Uri[] { uri }; mNfcAdapter = NfcAdapter.getDefaultAdapter(this); mNfcAdapter.setBeamPushUris(uris, this); findViewById(R.id.manual_beam_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { mNfcAdapter.invokeBeam(NfcTestActivity.this); } }); findViewById(R.id.intent_share_button).setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { Intent shareIntent = new Intent(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, uri); shareIntent.setType("image/jpg"); shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); // Specify the package name of NfcBeamActivity so that the tester don't need to // select the activity manually. shareIntent.setClassName(NFC_BEAM_PACKAGE, NFC_BEAM_ACTIVITY); try { startActivity(shareIntent); } catch (ActivityNotFoundException e) { Toast.makeText(NfcTestActivity.this, R.string.provisioning_byod_cannot_resolve_beam_activity, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Nfc beam activity not found", e); } } }); }
From source file:mai.whack.StickyNotesActivity.java
/** Called when the activity is first created. */ @Override// w ww . ja v a 2s .co m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mNfcAdapter = NfcAdapter.getDefaultAdapter(this); setContentView(R.layout.main); findViewById(R.id.write_tag).setOnClickListener(mTagWriter); // Handle all of our received NFC intents in this activity. mNfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); // Intent filters for reading a note from a tag or exchanging over p2p. IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED); try { ndefDetected.addDataType("text/plain"); } catch (MalformedMimeTypeException e) { } mNdefExchangeFilters = new IntentFilter[] { ndefDetected }; // Intent filters for writing to a tag IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED); mWriteTagFilters = new IntentFilter[] { tagDetected }; }
From source file:net.networksaremadeofstring.rhybudd.ViewZenossDeviceActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.view_zenoss_event_activity); triggerUIHandler = new Handler() { public void handleMessage(Message msg) { PopulatePager();/*from w ww .j a va2 s . c o m*/ } }; try { actionbar = getActionBar(); actionbar.setDisplayHomeAsUpEnabled(true); actionbar.setHomeButtonEnabled(true); actionbar.setSubtitle(getResources().getString(R.string.ViewDeviceActivitySubtitle)); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "OnCreate", e); } try { // Check for available NFC Adapter mNfcAdapter = NfcAdapter.getDefaultAdapter(this); if (null != mNfcAdapter) { // Register callback mNfcAdapter.setNdefPushMessageCallback(this, this); } } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "NFC", e); } try { currentDeviceID = getIntent().getStringExtra(ViewZenossDeviceFragment.ARG_UID); //currentDeviceName = getIntent().getStringExtra(ViewZenossDeviceFragment.ARG_HOSTNAME); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "currentDeviceID", e); } try { DeviceNames = getIntent().getStringArrayListExtra(ViewZenossDeviceFragment.ARG_DEVICENAMES); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "DeviceNames", e); } try { DeviceIDs = getIntent().getStringArrayListExtra(ViewZenossDeviceFragment.ARG_DEVICEIDS); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "DeviceIDs", e); } //Log.e("ViewZenossDevice", "Checking..."); if (null == DeviceNames || DeviceNames.size() == 0 || null == currentDeviceID || currentDeviceID.equals("")) { //Log.e("ViewZenossDevice", "No device names, fancy that!"); try { /*Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); NdefMessage msg = (NdefMessage) rawMsgs[0]; currentDeviceID = "/zport/dmd/Devices/" + msg.getRecords()[0].getPayload().toString();*/ (new Thread() { public void run() { try { RhybuddDataSource datasource = new RhybuddDataSource(ViewZenossDeviceActivity.this); datasource.open(); List<ZenossDevice> listOfDevices = datasource.GetRhybuddDevices(); datasource.close(); DeviceNames = new ArrayList<String>(); DeviceIDs = new ArrayList<String>(); for (ZenossDevice device : listOfDevices) { DeviceNames.add(device.getname()); DeviceIDs.add(device.getuid()); } processIntent(getIntent()); } catch (Exception e) { e.printStackTrace(); } } }).start(); } catch (Exception e) { e.printStackTrace(); } } else { try { triggerUIHandler.sendEmptyMessage(UI_POPULATE); } catch (Exception e) { BugSenseHandler.sendExceptionMessage("ViewZenossDevice", "triggerUIHandler UI_POPULATE", e); } } }
From source file:ykim81.cs.brown.ykim81.cardreader.CardReaderFragment.java
private void enableReaderMode() { Activity activity = getActivity();//from ww w . j a va 2 s .co m NfcAdapter nfc = NfcAdapter.getDefaultAdapter(activity); if (nfc != null) { nfc.enableReaderMode(activity, mLoyaltyCardReader, READER_FLAGS, null); } }
From source file:org.nick.ghettounlock.GhettoTrustAgent.java
@Override public void onCreate() { super.onCreate(); localBroadcastManager = LocalBroadcastManager.getInstance(this); IntentFilter filter = new IntentFilter(); filter.addAction(ACTION_GRANT_TRUST); filter.addAction(ACTION_REVOKE_TRUST); localBroadcastManager.registerReceiver(receiver, filter); setManagingTrust(getIsManagingTrust(this)); PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); nfcAdapter = NfcAdapter.getDefaultAdapter(this); installUnlockHandler();/* ww w . ja va2 s . c om*/ dpm = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE); long maxTimeToLock = dpm.getMaximumTimeToLock(null); Log.d(TAG, "max time to lock: " + maxTimeToLock); }