0

I am sorry if this question is not an "SO approved" type of question.

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.

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.

JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
  • Beacons just broadcast an identification number; the app on the client device has to be set up to scan for that particular identifier and take some action. Using an Android device as a beacon is probably overkill since you can but a beacon the size of a small coin battery or one that plugs into a USB port for about $15 – Paulw11 Feb 13 '16 at 07:27
  • The app has other functions too. `the app on the client device has to be set up to scan for that particular identifier and take some action`. Does that means that the app has to run on the background for this purpose? – JayVDiyk Feb 13 '16 at 07:41
  • Yes. On iOS you use CoreLocation background mode. I am sure there is something similar on Android. – Paulw11 Feb 13 '16 at 07:45
  • That being said, the best is to choose iBeacon over Eddystone or vice versa? @Paulw11 Thank you for you help! – JayVDiyk Feb 13 '16 at 07:47
  • Well, iOS has native support for iBeacon. I am not sure whether Eddystone is compatible – Paulw11 Feb 13 '16 at 07:48
  • Thanks for the help! @Paulw11 – JayVDiyk Feb 13 '16 at 07:49

1 Answers1

4

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. You need a device with Android 5.0+ that supports transmission (not all do). You can see a list of such devices here. The Android Beacon Library shows how to code transmission here. There is also an off-the-shelf Locate app that supports transmission here.

  • 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. Android can.

  • If you want your client app to detect quickly in the background on iOS, you are better off with iBeacon than Eddystone. Detection of iBeacon signals is optimized in the background on iOS and is built-in. Detection of Eddystone requires extra software and is not as fast.

  • 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. 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.

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.

CodeBender
  • 35,668
  • 12
  • 125
  • 132
davidgyoung
  • 63,876
  • 14
  • 121
  • 204
  • `The important part to understand us that the client code does all of the message sending locally`. If that is the case, how could some similar app manage to notify the client with something like "Discount 20% on all items". How is this possible? Thank you for answering! – JayVDiyk Feb 13 '16 at 12:39
  • Thanks for taking the time to answer. So, to conclude it all, there is no way to generate a Dynamic notification. Say, when the store app increase the discount to 30 percent or something like that? – JayVDiyk Feb 13 '16 at 15:02
  • Yes, this is possible. The common approach is to use a web service to do a lookup between beacon identifier and the notification message. This way you can change the offer remotely without having to update the app or change the beacon transmitter. – davidgyoung Feb 13 '16 at 15:30
  • Thank you for the patience and explanation!! – JayVDiyk Feb 13 '16 at 15:31