Sending URLs from Android to Windows Phone via NFC gives Play Store link

I am trying to use NFC to send a URL from an Android application to a WP8 phone.

When displayed on an Android device, the URL is sent correctly. However, when WP8 shines, IE downloads a link to the Play Store instead of the one I want to send (for example, http://www.stackoverflow.com ").

Link to the Play Store: " https://play.google.com/store/apps/details?id=com.example.conductrnfc&feature=beam ". Where "com.example.conductrnfc" is the name of the package in the project.

The code I used to generate the NFC message is below. Is there something I'm doing wrong here that breaks compatibility with WP8?

NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { NdefRecord uriRecord = NdefRecord.createUri(urlString); return new NdefMessage(new NdefRecord[] { uriRecord }); } }, this); 
+7
android windows-phone-8 nfc android-beam nfc-p2p
source share
2 answers

Can you try this:

 NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this); nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() { @Override public NdefMessage createNdefMessage(NfcEvent event) { byte[] payload = urlString.getBytes(); NdefRecord uriRecord = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_URI, new byte[0], payload); return new NdefMessage(new NdefRecord[] { uriRecord }); } }, this); 
+4
source share

Despite the fact that I'm still missing some debugging results from the OP, I thought I would give it a shot:

As discussed in the commands, it turned out that the createNdefMessage not called when interacting with the WP8 phone, it would be interesting why this adds and how to prevent it. Unfortunately, I have no details about the actual life cycle of the activity, so I can only guess what might go wrong.

  • One of the reasons why the registered createNdefMessage cannot be called is because the activity that registered the callback is no longer in the foreground. Thus, there may be a difference between the Android device and the WP8 device, which forces you to pause current activity.

  • Another reason is that the WP8 device intercepts the connection before the Android NFC stack has managed to call the createNdefMessage callback method. However, this should be detected, as the Beam user interface usually disappears before the user can click it.

One of the reasons why there may be reason 1 may be that the WP8 device itself sends an NDEF message that causes intent processing on the Android device. In this case, a method to overcome this problem may be to register for the foreground dispatching system. This would prevent regular processing of intentions and directly send all incoming NDEF messages to ongoing activities:

 @Override public void onResume() { super.onResume(); NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this); PendingIntent pi = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); adapter.enableForegroundDispatch(this, pi, null, null); } @Override public void onNewIntent(Intent intent) { if (intent != null) { String action = intent.getAction(); if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action) || NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action) || NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) { Log.d("NdefTest", "This problem was actually caused by an incoming NDEF message."); } } } 
0
source share

All Articles