android – 谷歌附近的API后台扫描在应用程序终止后无效

android – 谷歌附近的API后台扫描在应用程序终止后无效,第1张

概述我有kontakt.io信标,我尝试使用附近的API编写应用程序进行后台扫描. 我使用此方法订阅消息: SubscribeOptions options = new SubscribeOptions.Builder() // Finds messages attached to BLE beacons. See // https://develope 我有kontakt.io信标,我尝试使用附近的API编写应用程序进行后台扫描.

我使用此方法订阅消息:

SubscribeOptions options = new SubscribeOptions.Builder()            // Finds messages attached to BLE beacons. See            // https://developers.Google.com/beacons/            .setStrategy(Strategy.BLE_ONLY)            .build();    Nearby.Messages.subscribe(mGoogleapiclient,getPendingIntent(),options)            .setResultCallback(new ResultCallback<Status>() {                @OverrIDe                public voID onResult(@NonNull Status status) {                    if (status.isSuccess()) {                        Log.i(TAG,"subscribed successfully");                        mSubState = SubState.SUBSCRIBING;                        // Start background service for handling the notification.                        getActivity().startService(getBackgroundSubscribeServiceIntent());                    } else {                        Log.i(TAG,"Could not subscribe");                        handleUnsuccessfulNearbyResult(status);                    }                }            });

我的代码是根据这个示例:
https://github.com/googlesamples/android-nearby/tree/master/messages/NearbyBackgroundBeacons

我正确地收到消息,但当我杀死应用程序时,没有更多的消息来了.

杀死申请后有没有办法从附近获取消息?

解决方法 还没有真正尝试使用过一个,但你有没有考虑/使用 Service进行检查?根据描述:

A service can essentially take two forms:

Started

A service is “started” when an application component (such as an activity) starts it by calling startService(). Once started,a service can run in the background indefinitely,even if the component that started it is destroyed. Usually,a started service performs a single operation and does not return a result to the caller. For example,it might download or upload a file over the network. When the operation is done,the service should stop itself.

Bound

A service is “bound” when an application component binds to it by calling bindService(). A bound service offers a clIEnt-server interface that allows components to interact with the service,send requests,get results,and even do so across processes with interprocess communication (IPC). A bound service runs only as long as another application component is bound to it. Multiple components can bind to the service at once,but when all of them unbind,the service is destroyed.

您可以创建一个连续运行扫描的服务,直到您选择停止/销毁它为止.文档本身已经开始创建启动服务.请仔细阅读.

希望这会有所帮助.祝好运.

总结

以上是内存溢出为你收集整理的android – 谷歌附近的API后台扫描在应用程序终止后无效全部内容,希望文章能够帮你解决android – 谷歌附近的API后台扫描在应用程序终止后无效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1125777.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存