简体   繁体   English

NFC禁用/启用前台调度

[英]NFC disable/enable foreground dispatching at will

can we disable/enable foreground dispatching at will. 我们可以随意禁用/启用前台调度。 onresume/onpause will help us enable and disable when the activity comes back to focus and out of focus respectively. onresume / onpause将帮助我们启用和禁用活动重新聚焦和聚焦时。

is there a possibility to enable and then disable the foreground dispatching. 是否有可能启用然后禁用前台调度。

even tried to use IntentFilter writeTagFilters2[]= new IntentFilter[] { }; 甚至试图使用IntentFilter writeTagFilters2 [] = new IntentFilter [] {}; adapter.enableForegroundDispatch(this, pendingIntent, writeTagFilters2, null); adapter.enableForegroundDispatch(this,pendingIntent,writeTagFilters2,null);

to give no intents to react 没有意图做出反应

but it gives an error saying 但它说错了

Foreground dispatch can only be enabled when your activity is resumed. 只有在恢复活动时才能启用前台调度。

I believe you should be using disableForegroundDispatch(Activity) in order to remove the registration for the callback. 我相信你应该使用disableForegroundDispatch(Activity)来删除回调的注册。

From the documentation for enableForegroundDispatch : enableForegroundDispatch的文档:

This method must be called from the main thread, and only when the activity is in the foreground (resumed). 必须从主线程调用此方法,并且仅当活动位于前台(已恢复)时。 Also, activities must call disableForegroundDispatch(Activity) before the completion of their onPause() callback to disable foreground dispatch after it has been enabled. 此外,活动必须在完成onPause()回调之前调用disableForegroundDispatch(Activity),以在启用后禁用前台分派。

So provided your enable and disable calls reside between the onResume() and onPause() callbacks in the activity lifecycle , you can call them whenever. 因此,如果启用和禁用调用驻留在活动生命周期中onResume()onPause()回调之间,则可以随时调用它们。

Regarding your error, that code must be outside of the resume/pause events. 关于您的错误,该代码必须在resume / pause事件之外。 Is it in your onCreate() method by any chance? 它是否在你的onCreate()方法中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM