Disable Android Beam for selected activities

我们两清 提交于 2020-01-02 17:15:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!