作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对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/
我是一名优秀的程序员,十分优秀!