Launch App Via Nfc And Send A Ndef Message Back When Started
Solution 1:
A one-tap approach is not possible using Beam on two Android devices (note that with other devices, particularly if one is Android and one is a dedicated NFC reader or a device where you can control the NFC functionality on a low level or a device that emulates an NFC tag).
However, a two-tap approach is possible between two Android devices with only little modifications to your existing scenario. You simply need to add a foreground dispatch that intercepts your incoming NDEF message and consequently prevents Android from restarting your activity:
@OverridepublicvoidonResume() {
super.onResume();
NfcAdapteradapter= NfcAdapter.getDefaultAdapter(this);
PendingIntentpi= PendingIntent.getActivity(
this,
0,
newIntent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
0);
adapter.enableForegroundDispatch(this, pi, null, null);
}
EDIT
A more general approach for the two-tap scenario would be to send the NDEF message from device A to device B on the first tap. This NDEF message starts the app on device B. Immediately after sending the NDEF message, device A stop sending the message. When the app on device B is active, it registeres its own NDEF message for Beam. Then, in the second tap, the Beam UI will be shown on device B and clicking the Beam screen will send the response NDEF message to device A.
Note that device A must stop sending its initial NDEF message. Otherwise, the app on device B will receive a new NDEF message and, consequently, won't open the Beam UI.
Post a Comment for "Launch App Via Nfc And Send A Ndef Message Back When Started"