(using 4.1.1 JellyBean on a Nexus S) I am trying to follow these instructions, but the restrictions on in which activities setNdefPushMessage()
can be used are to me somewhat vague. Presently my app, which has an activity for handling http requests via:
<activity android:name=".HandleUrlActivity"
android:label="@string/title_handle_url_message" >
<intent-filter>
<action android:name="android.intent.action.VIEW" /
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
</intent-filter>
</activity>
crashes with:
java.lang.IllegalStateException: API cannot be called while activity is paused
when setNdefPushMessage() is called within HandleUrlActivity().
In what activities can setNdefPushMessage() be used? Or how can I keep an activity running until the Ndef is served and how do I know when that activity can return/exit? Calling:
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
nfcAdapter.setNdefPushMessage(ndef, this);
nfcAdapter.wait();
gives the above error with or without the wait. Clearly setNdefPushMessage()
needs some support mechanisms to handle the wait-for-nfc-receive-capable-device-proximity and then send events and I expected it to block until all this was complete, but apparently it does not.
(enableForegroundNdefPush/disableForegroundNdefPush
apparently addressed this issue but appear to have been deprecated for ICS/JB with claims that setNdefPushMessage
handles all this...)