任何人都可以分享任何步骤,以便在beacon进入android棒棒糖的特定范围时显示通知。
答案 0 :(得分:2)
您可以使用Android Beacon Library执行此操作,代码如下:
@Override
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
for (Beacon beacon: beacons) {
if (beacon.getDistance() < 5.0) {
Log.d(TAG, "I see a beacon that is less than 5 meters away.");
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setContentTitle("Beacon Reference Application")
.setContentText("An beacon is nearby.")
.setSmallIcon(R.drawable.ic_launcher);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
PendingIntent resultPendingIntent =
stackBuilder.getPendingIntent(
0,
PendingIntent.FLAG_UPDATE_CURRENT
);
builder.setContentIntent(resultPendingIntent);
NotificationManager notificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1, builder.build());
}
}
}
此处详细信息:
http://altbeacon.github.io/android-beacon-library/distance-triggering.html
答案 1 :(得分:0)
只需按照教程:http://developer.estimote.com/eddystone/即可开始使用。然后你可以检索有关信号的信息:
Beacon nearestbeacon;
(...)
// computeAccuracy gives you distance in meters
Utils.computeAccuracy(nearestBeacon);
// computeProximity gives you state like IMMEDIATE/NEAR/FAR
Utils.computeProximity(nearestBeacon);