Java Tunning我的android到信标和检测

Java Tunning我的android到信标和检测,java,android,Java,Android,这是正确的做法吗?我正在使用这个样本 我也有一个问题,即didenterregion和DidRangeBeaConsincinRegion被多次激发,因此我多次向用户发送许多通知。它对用户不友好。应该多次调用didRangeBaconRegion回调函数,这就是测距的工作原理。当检测到信标时,它大约每秒调用一次,告诉您它在那里,并给您一个距离估计值 如果您希望在第一次调用此方法时仅触发一次通知,则可以为此特定信标设置标志 下面是一些代码的示例,您可以使用这些代码: // Add this to

这是正确的做法吗?我正在使用这个样本


我也有一个问题,即didenterregion和DidRangeBeaConsincinRegion被多次激发,因此我多次向用户发送许多通知。它对用户不友好。

应该多次调用
didRangeBaconRegion
回调函数,这就是测距的工作原理。当检测到信标时,它大约每秒调用一次,告诉您它在那里,并给您一个距离估计值

如果您希望在第一次调用此方法时仅触发一次通知,则可以为此特定信标设置标志

下面是一些代码的示例,您可以使用这些代码:

// Add this to the top of your class
private HashMap<String,Boolean> mAlreadySentNotification = new HashMap<String,Boolean>();

...

// Add this to the inside of your didRangeBeaconsInRegion method
if (mAlreadySentNotification.get(beacon.toString())) {
  mAlreadySentNotification.put(beacon.toString(), true);
  // Send notification here.
}
//将其添加到类的顶部
private HashMap mAlreadySentNotification=新建HashMap();
...
//将此添加到您的DidRangeBeanConsinRegion方法的内部
if(mAlreadySentNotification.get(beacon.toString())){
mAlreadySentNotification.put(beacon.toString(),true);
//在这里发送通知。
}

应该多次调用
didRangeBeanConsincin区域的回调函数,这就是测距的工作原理。当检测到信标时,它大约每秒调用一次,告诉您它在那里,并给您一个距离估计值

如果您希望在第一次调用此方法时仅触发一次通知,则可以为此特定信标设置标志

下面是一些代码的示例,您可以使用这些代码:

// Add this to the top of your class
private HashMap<String,Boolean> mAlreadySentNotification = new HashMap<String,Boolean>();

...

// Add this to the inside of your didRangeBeaconsInRegion method
if (mAlreadySentNotification.get(beacon.toString())) {
  mAlreadySentNotification.put(beacon.toString(), true);
  // Send notification here.
}
//将其添加到类的顶部
private HashMap mAlreadySentNotification=新建HashMap();
...
//将此添加到您的DidRangeBeanConsinRegion方法的内部
if(mAlreadySentNotification.get(beacon.toString())){
mAlreadySentNotification.put(beacon.toString(),true);
//在这里发送通知。
}

不要对自己试图解释的问题发表评论。如果你有更多的信息要添加到你的问题中,你的问题和添加到那里。不要在你自己的问题上发表评论试图解释它。如果您有更多信息要添加到您的问题中,请选择您的问题并将其添加到那里。谢谢您的回答。您的解决方案很好,但有一个bug。例如,我检测到信标1,并将该信标1设置为true,以便只发送一个通知。但是,我确实需要将信标1重置为false,以便我在30分钟后或一天后再次发送通知?我如何处理这种情况。谢谢你的回答。您的解决方案很好,但有一个bug。例如,我检测到信标1,并将该信标1设置为true,以便只发送一个通知。但是,我确实需要将信标1重置为false,以便我在30分钟后或一天后再次发送通知?我如何处理这种情况。
// Add this to the top of your class
private HashMap<String,Boolean> mAlreadySentNotification = new HashMap<String,Boolean>();

...

// Add this to the inside of your didRangeBeaconsInRegion method
if (mAlreadySentNotification.get(beacon.toString())) {
  mAlreadySentNotification.put(beacon.toString(), true);
  // Send notification here.
}