简体   繁体   English

充当信标的 Android 设备

[英]Android Device to Act as Beacon

I am sorry if this question is not an "SO approved" type of question.如果这个问题不是“SO 批准”类型的问题,我很抱歉。

I would like to develop an app that act as a beacon (among of other functionality).我想开发一个充当信标(以及其他功能)的应用程序。 This app will be installed on an Android device.此应用程序将安装在 Android 设备上。

I am very new at all these Bluetooth programming and I would like to get some answers on these questions:我对所有这些蓝牙编程都很陌生,我想就这些问题得到一些答案:

  1. Can anyone point me on the right part as where to start?谁能指出我正确的部分从哪里开始?

  2. How client app get notification from the beacon?客户端应用程序如何从信标获取通知? Can anyone explain how it works?谁能解释一下它是如何工作的?

Thank you and sorry for these questions.感谢并抱歉回答这些问题。

A few points:几点:

  • Yes, you can make a beacon app that sends both an iBeacon and/or an Eddystone beacon transmission from an Android device.是的,您可以制作一个信标应用程序,从 Android 设备发送 iBeacon 和/或 Eddystone 信标传输。 You need a device with Android 5.0+ that supports transmission (not all do).您需要一台支持传输的 Android 5.0+ 设备(并非所有设备都支持)。 You can see a list of such devices here .您可以在此处查看此类设备的列表。 The Android Beacon Library shows how to code transmission here . Android Beacon 库展示了如何在此处进行代码传输。 There is also an off-the-shelf Locate app that supports transmission here.这里还有一个现成的Locate 应用程序支持传输。

  • It is also possible to make a transmitter beacon app on iOS, but iOS only supports transmission of iBeacon packets (you cannot transmit Eddystone on iOS), and iOS cannot transmit when the app is in the background.也可以在iOS上制作发射器beacon app,但iOS只支持iBeacon数据包的传输(iOS上不能传输Eddystone),当app在后台时iOS无法传输。 Android can.安卓可以。

  • If you want your client app to detect quickly in the background on iOS, you are better off with iBeacon than Eddystone.如果您希望您的客户端应用程序在 iOS 的后台快速检测,那么使用 iBeacon 比使用 Eddystone 更好。 Detection of iBeacon signals is optimized in the background on iOS and is built-in. iBeacon 信号的检测在 iOS 的后台进行了优化并且是内置的。 Detection of Eddystone requires extra software and is not as fast. Eddystone 的检测需要额外的软件,而且速度没有那么快。

  • To send a notification on beacon discovery you simply write code in the client app that detects the unique beacon identifier then creates a local notification message keyed off the beacon identifier and sends it to the user.要发送有关信标发现的通知,您只需在客户端应用程序中编写代码来检测唯一的信标标识符,然后根据信标标识符创建本地通知消息并将其发送给用户。 The important part to understand us that the client code does all of the message sending locally.理解我们的重要部分是客户端代码在本地完成所有消息发送。 All the beacon app does is transmit a unique identifier that the client app receives.信标应用程序所做的只是传输客户端应用程序接收到的唯一标识符。

To illustrate the point about how you send local notifications based on beacon identifiers, here is some sample code for iOS.为了说明如何根据信标标识符发送本地通知,这里有一些适用于 iOS 的示例代码。 This code runs on the client app.此代码在客户端应用程序上运行。 The Beacon simply sends out a transmission with specific beacon identifiers, and the client app reads them and acts appropriately. Beacon 只是发送带有特定信标标识符的传输,客户端应用程序读取它们并采取适当的行动。

var lastNotificationTime = NSDate(timeIntervalSince1970: 0) // Initialize last Notification time to a long time ago

func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
  // Only send notification if we have not done so in the last hour (3600 seconds)
  if (lastNotificationTime.timeIntervalSinceNow < -3600.0) {
    for beacon in beacons {
      // Send a 20% off notification for beacon with identifiers major 1, minor 2
      if beacon.major.intValue == 1 && beacon.minor.intValue == 2 {
        let localNotification = UILocalNotification()
        localNotification.alertTitle = "Discount 20% on all items"
        dispatch_async(dispatch_get_main_queue()) {
          UIApplication.sharedApplication().presentLocalNotificationNow(localNotification)
        }
      }
    }
  }
}

Full Disclosure: I am the lead developer on the Android Beacon Library open source project and the author of the Locate app.全面披露:我是 Android Beacon Library 开源项目的首席开发人员,也是 Locate 应用程序的作者。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM