Android

An interesting thing to note in our Android app is that our app would be making use of open source software developed by Google, which makes our life easier by parsing Eddystone advertisement data. We begin by creating an empty project in the Android Studio by the name of AndroidBeaconScanner. We have already done the project creation multiple times and hence we won't be repeating that here.

During the project creation, choose the minimum API Level to be 21, since many of the API calls require minimum API Level to be 21.

Once we have finished creating our empty project, as a first step, we can define some simple user interface as follows:

  1. We take a slightly different approach this time. After creating the project, rather initializing the UI as we did earlier, this time we go ahead and include(as described in step 2) the software which is provided "as is" by Google. The advantage of including this software in the very first step is that we won't be running into any build issues later on due to undefined classes.

 

  1. We recommend creating a separate package for the software, which needs to be included as is. This can be done by navigating to File | New | Package, selecting Package and choosing a destination directory which is Java in our case. Please give your package a meaningful name. For simplicity, we just named ours as google as shown in the following screenshot:
Figure 13: Including software from Google
  1. As shown in the preceding screenshot, we would need the following four files:
    • BluetoothUuid.java
    • ScanRecord.java
    • EddystoneBeacon.java
    • UrlDevice.java

These files are already hosted in Google's Physical Web repository.

Google's physical web repository is available here: https://github.com/google/physical-web.

We could have also included these files as a part of a bigger package/library, but we do not need everything else. Hence to slim it down, we shall include on only these four files. You can include these files by simply downloading those from GitHub and copying and pasting them in the google package. Please do remember the to change the package name statement at the very start(top of each file) with your own package name as shown in the preceding screenshot. We will explain the purpose of each of these files:

  • BluetoothUuid.java: This contains standard service IDs as defined in Bluetooth assigned number documents. It also contains various methods to convert/parse bytes to UUID(s). It is used internally by ScanRecord.java to parse Service UUID(s).
To know more about Bluetooth assigned numbers in Service Discovery Protocol (SDP), visit https://www.bluetooth.com/specifications/assigned-numbers/service-discovery.

The BluetoothUuid.java file is hosted at Google's Physical Web repository on GitHub: https://github.com/google/physical-web/blob/master/android/PhysicalWeb/app/src/main/java/org/physical_web/physicalweb/ble/BluetoothUuid.java. Alternatively, you can also download it (plus the other three files) prebundled as a part of the current app we are building. The link for the app's code on Github, as always, is provided at the end of this section.

In our app, we would be dealing specifically with Eddystone-URL packets.

To know more about Eddystone-URL packet format, visit https://github.com/google/eddystone/tree/master/eddystone-url.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.64.132