本文介绍了应用程序终止后,Google附近的API后台扫描不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有kontakt.io信标,并尝试使用附近的API编写后台扫描应用程序。



我使用此方法订阅邮件:

  SubscribeOptions options = new SubscribeOptions.Builder()
//查找附加到BLE信标的消息。请参阅
// 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状态状态){
if(status.isSuccess()){
Log.i(TAG,订阅成功);
mSubState = SubState.SUBSCRIBING;
//开始处理通知的后台服务
getActivity()。startService(getBackgroundSubscribeServiceIntent());
} else {
Log.i(TAG,无法订阅);
handleUnsuccessfulNearbyResult(status);
}
}
});

我的代码依据以下示例:



我正确接收邮件,但是当我杀了应用程序时,没有更多邮件来。

有没有办法在查杀应用程序后从附近获取消息?

解决方案

还没有真正尝试过使用其中一个,但是您是否考虑/使用?根据描述:

您可以创建一个 Service ,它会持续运行扫描,直到您选择停止/销毁它为止。文档本身已经有了创建启动服务的功能。只要仔细阅读。



希望这有助于某种方式。祝你好运。


I have kontakt.io beacon and I try to write application for background scanning with nearby API.

I use this method to subscribe messages:

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);
                    }
                }
            });

My code is according to this sample:https://github.com/googlesamples/android-nearby/tree/master/messages/NearbyBackgroundBeacons

I´m receiving messages correctly, but when I kill application no more message come.

Is there any way to get messages from nearby after killing application?

解决方案

Haven't really tried using one yet, but have you considered/checked on using a Service? As per the description:

You could create a Service that runs the scan continuously until such time that you choose to stop/destroy it. The docs itself already has step on Creating a Started Service. Just read it thoroughly.

Hope this helps somehow. Good luck.

这篇关于应用程序终止后,Google附近的API后台扫描不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 02:13