Using a NdefLaunchAppRecord restarts the app even if it is already open

Oct 1, 2013 at 11:58 AM
I already posted this question to StackOverflow but didn't get any response there. I will answer reference any solution from CodePlex on StackOverflow of course.
0 down vote favorite

I want my Windows Phone 8 app to be opened if a NDEF message is received from another WP8 device. This works fine as long as the app is not open on the target device. The user is asked if he wants to open the app. If the app is already open the user will still be prompted if he wants to open it as if it wasn't already open. I want the message to be sent if the app is already open without WP8 displaying any alerts.

Is there a way to achieve this? This is what I have tried so far:
NdefLaunchAppRecord appLaunchRecord = new NdefLaunchAppRecord();
appLaunchRecord.AddPlatformAppId("WindowsPhone", launchAppString);
appLaunchRecord.Arguments = "Test";

NdefMessage ndefMessage = new NdefMessage { appLaunchRecord };

var msgId = ProximityDevice.GetDefault().PublishBinaryMessage(
    "NDEF", ndefMessage.ToByteArray().AsBuffer(), MessageWrittenHandler);
Oct 1, 2013 at 3:08 PM
Unfortunately, it is not possible with WP8.0 to get rid of prompts to launch the app through the LaunchApp record or the custom URI protocol, even it is already running. We do hope that Microsoft will change this behaviour in future versions of the OS, as it doesn't make much sense.

As a workaround, there is not much you can do. The only option is:

If you know the app is already running, you can send a custom NDEF record to the other device (of the external type; use the NdefRecord class of the library directly to work with this one). The OS will not interfere with those records and will not show a message. If your app is already running, you can subscribe to all NDEF messages and receive those messages as well. Note that it is not possible to launch the app on WP using custom records - this method only works when the app is running.

If you want to be compatible to NDEF standards to ensure interoperability, the type of your record has to follow certain naming conventions - e.g., "" would be a valid name. Read the NDEF specs on type name rules.

To create and test such records of the external type, you create them with the "NFC interactor" app for WP - create a "Custom" record.
Oct 3, 2013 at 10:09 AM
Thank you for your extensive answer.

I cannot use it however as the target device may be running Android which does not allow to use NFC except through the Android Beam interface. I don't see a way there to wait for an incoming message except for manually blocking the UI which is really ugly. Otherwise I risk sending a LaunchApp record from Android even if the app on the receiving WP8 device is already running. This is too much work for an ugly or only partially (WP8 to WP8) working solution.

In any way I would be limited to use URI records as Android does not like LaunchApp records (It hides following records containing the actual payload.) which in turn would mean I have to sacrifice the advantage of LaunchApp records which point the user to the store if the app is not installed.

I'll require the WP8 user to have the app open, this seems to be the only simple, clean and consistent solution.
Oct 3, 2013 at 11:34 AM
You could also use this method for Android - just create a message that contains as the 1st record a record of the external type, and as the second record with the Android Application Record. Through that, you can connect your Android app to receive the message, no matter what is present in the first record (even if it's a LaunchApp, which is Microsoft-specific).

AAR are supported on all Android 4.x+ devices; if you absolutely have to provide the same UX even on Android 2.x, the only option is to use a custom URI scheme. But these are not unique (anyone can register their apps for your URI scheme as well) and you can't prevent the operating system NFC prompt from appearing on Windows Phone.
Oct 8, 2013 at 8:24 AM
We target Android 4.3, maybe even 4.4 when it is released. Compatibility is not our concern at the moment.

I think I wasn't specific enough. Android does launch the app if the NDEF message contains a LaunchApp record followed by an AAR. AAR however cannot be used to transmit custom user data.
It seems to be common practice to send a record containing the payload (TNF 2 for example) followed by an AAR. This ensures the app gets launched if it is installed. If it isn't we don't care about the payload. Android will then use the AAR to point to the app in the store.
This leads to de behaviour i described in my last answer. Android does not recognise the first record and decides ignore everything except for the AAR.

I hope this makes sense to you? If not, just ask. I don't have a really satisfactory solution yet.