问题
I'm working with NFC on Android, specifically with Android Beam. My question is: is it possible to disable Android Beam support for an activity?
This is what some system applications do, such as messaging: if another phone is put close, my phone vibrates but the "Touch to beam" screen doesn't appear and the other phone doesn't receive anything.
EDIT: Calling:
NfcAdapter.setNdefPushMessage(NdefMessage message, Activity activity, Activity... activities)
in onResume()
with a null
message should do the trick (the doc says: "Pass a null NDEF message to disable foreground NDEF push in the specified activities.") but it doesn't work.
Thanks
回答1:
When I do it like this, It works like a charm.
NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
adapter.setNdefPushMessage(null, this, this);
回答2:
There isn't a way to do this currently. Maybe you can provide a menu option to disable NFC in your app? Why do you want to do this, by the way?
EDIT:
Sorry, there is a way to do this. Call setNdefPushMessage() in the activities that you don't want to push anything with a null NDEF message. Let me know if that works.
来源:https://stackoverflow.com/questions/9020901/disable-android-beam-for-selected-activities