How Can I Send A String Through Nfc While Screen-pinning?
Solution 1:
I'm not sure if this actually answers your question, but I'd like to summarize my findings:
When trying your example on Android 5.0.1 (LRX22C on Nexus 4), the receiving side automatically unpins the screen upon receiving the NDEF message and (re-)starts the activity. So it seems that the intent filter that is registered in the manifest gets priority over (manual?) screen pinning.
I'm aware that this does not quite match the experiences described in the question. I'm wondering if this is due to the different Android version (5.0 vs. 5.0.1) or due to the use of manual screen pinning instead of programatic screen pinning...
In my test setup, I was able to solve the problem (i.e. prevent the activity from getting automatically unpinned) by using the foreground dispatch system to register the activity to receive its NDEF message:
In your onResume()
method create a pending intent like this and enable foreground dispatch:
PendingIntentpi=this.createPendingResult(0x00A, newIntent(), 0);
nfcAdapter.enableForegroundDispatch(this, pi, null, null);
You will then receive intents notifying you about discovered tags through the activity's onActivityResult()
method:
@OverrideprotectedvoidonActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case0x00A:
onNewIntent(data);
break;
}
}
Moreover, you have to disable the foreground dispatch in your onPause()
method:
nfcAdapter.disableForegroundDispatch(this);
Post a Comment for "How Can I Send A String Through Nfc While Screen-pinning?"