Android 棒棒糖显示通知,如果信标在特定范围内
Android lollipop show notification, if beacon in specific range
当信标进入 android 棒棒糖的特定范围时,任何人都可以分享任何显示通知的步骤。
您可以使用 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
只需按照教程: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);
当信标进入 android 棒棒糖的特定范围时,任何人都可以分享任何显示通知的步骤。
您可以使用 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
只需按照教程: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);