gpt4 book ai didi

java - 仅当在一定时间内检测到信标时才显示通知

转载 作者:行者123 更新时间:2023-12-02 02:55:07 24 4
gpt4 key购买 nike

我对andriod应用程序编程非常陌生,想询问有关信标的问题。

目前,我正在使用 AltBeacon android-beacon-library 编写应用程序。我喜欢实现一项功能:

理想情况下,我希望当用户靠近特定信标时显示通知。但是,我只希望当用户在该信标周围停留超过 30 秒时才显示通知。如果用户只是走过信标,那么我不希望显示通知。

请问有现成的方法吗?我知道有一种名为“startMonitoringBeaconsInRegion”的方法,但我真的不知道这是否是合适的方法。任何帮助将不胜感激。

最佳答案

使用后台服务通过计时器获取信标可用性。当您收到信标存在时启动计时器,如果信标在该位置可用 30 秒,则在 30 秒后触发通知,否则重置计时器。

信标后台搜索:http://developer.estimote.com/android/tutorial/part-2-background-monitoring/

上面的教程链接看起来很有希望

    //start when found beacon in background

Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {

getActivity().runOnUiThread(new Runnable() {
public void run() {
try {
//send notification
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}, 30000);

//如果信标状态为假或不可用则重置

   if (timer != null) {
timer.cancel();
}

关于java - 仅当在一定时间内检测到信标时才显示通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43228809/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com