android - 接近信标 API : Android and Nearby

标签 android beacon google-nearby google-beacon-platform google-proximity-api

我的 Android 应用程序用于广播信标,这些信标通过“附近”作为带有 URL 链接的通知传送到附近的设备。

Google 宣布 they are going to close this service .

他们建议使用Proximity Beacons API

阅读文档后,我发现我需要通过 REST-API 注册每个信标,使用 OAuth 和 API 进行身份验证(同时),他们还提到了有关 Google 地方信息等内容。

看起来很复杂。

我不明白:这些信标是否会通过“附近”和我的 URL 链接传递给附近的用户?以前是如何工作的。

也许有一个 Android 库? 我发现this 。但这仅用于“扫描”。我不明白这是做什么用的。是否可以像以前一样将信标广播到附近的其他设备?

谢谢

最佳答案

Google Nearby 提供了一种向信标附近的 Android 设备发送通知的方法即使用户没有安装您的第三方应用。现在,Nearby 已停止使用,这不再可能。您现在必须在设备上安装第三方应用程序,才能向用户发送有关信标检测的通知。

最简单的方法是构建一个基本的 Android 应用程序,该应用程序仅监听信标并在检测到信标时发送通知。您可以使用 Google Pproximity Beacons API 来完成此操作,这有点复杂,因为它需要向 Google 服务器注册您的信标,启用该服务,并将 API key 嵌入到您的应用中。

一种更简单的方法是使用开源 Android Beacon 库,该库更加成熟,并且没有服务器或许可要求。您可以阅读其工作原理 here 。发送有关信标检测的通知非常简单。只需链接到库,然后将此代码 fragment 添加到自定义 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())
}

无论您使用哪种 APi,关键的障碍都是让用户安装您的应用。除非他们这样做,否则他们将不会收到通知。 Google Nearby 通过将自身嵌入到 Google Play 服务客户端应用程序中,看似无需应用程序就能实现这一目标,该应用程序预装在中国境外的大多数 Android 设备上。本质上,谷歌是通过他们的应用程序为你发送通知的。现在,Google 宣布将不再这样做。

同样,唯一的选择是构建和分发您自己的应用程序来检测信标并发送通知。

全面披露:我是 Android Beacon Library 的首席开发人员开源项目。

关于android - 接近信标 API : Android and Nearby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53046009/

相关文章:

android - Android 权限 READ_GSERVICES 到底是做什么用的?

java - 关于 didRangeBeaconsInRegion

android - JSON 数组到 GridView 中的 ImageView

android - 如何从后台服务更新多个 Android Activity 中的 UI

android - 广告数据太大 Eddystone Beacon

ios - 信标测距与 BLE 扫描

android - 谷歌附近的通知分析

ios - Google Nearby Messages API 破坏了应用程序图标

android - Google 附近的通知无法正常工作

java - android - 如何检查进程是否存活?