Java Code Examples for android.nfc.NfcAdapter#setNdefPushMessageCallback()
The following examples show how to use
android.nfc.NfcAdapter#setNdefPushMessageCallback() .
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: BeamController.java From AndroidChromium with Apache License 2.0 | 6 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (ApiCompatibilityUtils.checkPermission( activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) { return; } try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 2
Source File: BeamController.java From 365browser with Apache License 2.0 | 6 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (ApiCompatibilityUtils.checkPermission( activity, Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) { return; } try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 3
Source File: LyricsViewFragment.java From QuickLyric with GNU General Public License v3.0 | 6 votes |
@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(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); } } }
Example 4
Source File: NfcProvisioningFragment.java From enterprise-samples with Apache License 2.0 | 5 votes |
@Override public void onStart() { super.onStart(); Activity activity = getActivity(); NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity); if (adapter != null) { adapter.setNdefPushMessageCallback(this, activity); } getLoaderManager().initLoader(LOADER_PROVISIONING_VALUES, null, this); }
Example 5
Source File: BeamActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
private void setBeamMessage() { NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this); nfcAdapter.setNdefPushMessageCallback( new NfcAdapter.CreateNdefMessageCallback() { public NdefMessage createNdefMessage(NfcEvent event) { String payload = "Beam me up, Android!\n\n" + "Beam Time: " + System.currentTimeMillis(); NdefMessage message = createMessage(payload); return message; } }, this); }
Example 6
Source File: BeamController.java From delion with Apache License 2.0 | 5 votes |
/** * If the device has NFC, construct a BeamCallback and pass it to Android. * * @param activity Activity that is sending out beam messages. * @param provider Provider that returns the URL that should be shared. */ public static void registerForBeam(final Activity activity, final BeamProvider provider) { final NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(activity); if (nfcAdapter == null) return; if (activity.checkPermission(Manifest.permission.NFC, Process.myPid(), Process.myUid()) == PackageManager.PERMISSION_DENIED) return; try { final BeamCallback beamCallback = new BeamCallback(activity, provider); nfcAdapter.setNdefPushMessageCallback(beamCallback, activity); nfcAdapter.setOnNdefPushCompleteCallback(beamCallback, activity); } catch (IllegalStateException e) { Log.w("BeamController", "NFC registration failure. Can't retry, giving up."); } }
Example 7
Source File: NfcProvisioningFragment.java From android-NfcProvisioning with Apache License 2.0 | 5 votes |
@Override public void onStart() { super.onStart(); Activity activity = getActivity(); NfcAdapter adapter = NfcAdapter.getDefaultAdapter(activity); if (adapter != null) { adapter.setNdefPushMessageCallback(this, activity); } getLoaderManager().initLoader(LOADER_PROVISIONING_VALUES, null, this); }