asf*_*asf 2 android google-beacon-platform beacon google-nearby google-proximity-api
我的 Android 应用程序用于广播信标,这些信标作为带有 URL 链接的通知传送到附近的设备。
谷歌宣布他们将关闭这项服务。
他们推荐使用Proximity Beacons API
阅读文档后,我知道我需要通过 REST-API 注册每个信标,使用 OAuth 和 API 进行身份验证(同时),他们还说了一些关于 Google Places 的内容等等。
看起来很复杂。
我不明白:这些信标会通过我的 URL 链接通过 Nearby 传送给附近的用户吗?以前是怎么工作的。
也许有一个Android库?我找到了这个。但它仅用于“扫描”。我不明白是为了什么。像以前那样向附近的其他设备广播信标是不可能的吗?
谢谢
Google Nearby 提供了一种向靠近您的信标的 Android 设备发送通知的方法,即使用户没有安装您的第三方应用程序。现在 Nearby 已停产,这不再可能。您现在必须在设备上安装第三方应用程序,以便向用户发送有关信标检测的通知。
最简单的方法是构建一个基本的 Android 应用程序,它只侦听信标并在检测到信标时发送通知。您可以使用 Google Pproximity Beacons API 执行此操作,这有点复杂,因为它需要在 Google 的服务器上注册您的信标,启用该服务,并在您的应用程序中嵌入一个 API 密钥。
一个更简单的方法是使用开源 Android Beacon 库,它更加成熟并且没有服务器或许可要求。您可以在此处阅读其工作原理。发送有关信标检测的通知非常简单。只需链接到库,即可将此代码片段添加到自定义 Android 应用程序类中。
@Override
public void onCreate() {
super.onCreate();
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
beaconManager.getBeaconParsers().add(new BeaconParser().
setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
Region region = new Region("com.example.myapp.boostrapRegion", null, null, null);
RegionBootstrap regionBootstrap = new RegionBootstrap(this, region);
}
@Override
public void didEnterRegion(Region region) {
NotificationCompat.Builder builder =
new NotificationCompat.Builder(this)
.setContentTitle("Beacon Reference Application")
.setContentText("A 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())
}
Run Code Online (Sandbox Code Playgroud)
无论您使用哪种 API,关键的障碍是让用户安装您的应用程序。除非他们这样做,否则他们将不会收到通知。Google Nearby 通过将自身嵌入到预装在中国以外的大多数 Android 设备上的 Google Play 服务客户端应用程序中,似乎无需应用程序即可实现这一目标。本质上,谷歌是通过他们的应用程序为你发送通知。现在,谷歌宣布将不再这样做。
同样,唯一的选择是构建和分发您自己的应用程序来检测信标并发送您的通知。
全面披露:我是Android Beacon 库开源项目的首席开发人员。
| 归档时间: |
|
| 查看次数: |
799 次 |
| 最近记录: |