gpt4 book ai didi

Android iBeacon 接收单个指定信号

转载 作者:行者123 更新时间:2023-11-29 00:19:45 24 4
gpt4 key购买 nike

我在我的 iBeaconProject 中使用 BroadcastReceiver 从 onReceive 接收一系列信号。我想做的是只跟踪一个信标(我指定的)以及它从我的手机到信标的距离。有什么想法吗,伙计们?请帮我!我正在使用 http://www.radiusnetworks.com .我正在使用以下 onReceive 函数获取一系列信号。我该怎么做?提前致谢!

BroadcastReceiver bReceiver = new BroadcastReceiver() {


@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
int countBea = 0;
if (intent.getAction().equals(intentname) && intent.getExtras() != null && intent.getExtras().containsKey(intentname)) {
Collection<IBeacon> beaconsCol = (Collection<IBeacon>)intent.getExtras().getSerializable(intentname);

for (IBeacon bea : beaconsCol) {

Log.d("beac receive!","receive! "+bea.getProximityUuid()+" "+bea.getMajor()+" "+bea.getMinor()+" "+bea.getAccuracy()+" "+bea.getProximity()+" "+bea.getRssi()+" "+bea.getTxPower());
countBea++;
if(((mainActivity)getActivity()).UUIDValue.equalsIgnoreCase(bea.getProximityUuid())
&& ((mainActivity)getActivity()).MajorValue == bea.getMajor()
&& ((mainActivity)getActivity()).MinorValue == bea.getMinor()) {
update(bea.getProximityUuid(), +bea.getMajor(), bea.getMinor(), bea.getAccuracy());

} else if (((mainActivity)getActivity()).UUIDValue.equalsIgnoreCase(bea.getProximityUuid())
&& (((mainActivity)getActivity()).MajorValue == 0 ||
((mainActivity)getActivity()).MinorValue == 0)) {
updateNILMajorMinor();
} else {
updateMultipleBeaconsDetected();
}

}
System.out.println("COUNTBEAC " + countBea);

}
}
};

最佳答案

很高兴看到 for-each 循环。

在其中,您可以识别要跟踪的信标,

for (IBeacon bea : beaconsCol) {
//in the following if, identify the specified beacon
// this will remain the same for every refresh
if(bea.getProximityUuid().equals("match it here") && bea.getMajor()==major
&& bea.getMinor()==minor){
//now display that beacon's proximity and accuracy
//the same code will update a textview or notification every time

// here you will have 1 beacon at a time, can add that to a global list
}
}

您能给出具体的实现思路吗?

您的代码是否定期进入onReceive?

关于Android iBeacon 接收单个指定信号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909493/

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