XYO Foundation Dev Portal
  • Guides

›SDKs

Getting Started

  • Getting Started

Updates

  • Latest Updates
  • News Archive

Changemaker Challenge

  • UC San Diego and XYO

Using our Mobile SDKs

  • SDK Guide

XYO Foundation

  • Open Source Initiative

XYO Network App

  • How To Use

Explore App

  • How To Use

Bridge

  • Bridge X

Smart Contract Apps

  • Dapploy
  • Dapper
  • SCSC Library

SDKs

  • Android SDK
  • Swift SDK
  • Node Core SDK
  • Swift Core SDK
  • Kotlin Core SDK

Tools

  • XYO Tools

ANDROID SDK

The XYO Foundation provides this source code available in our efforts to advance the understanding of the XYO Procotol and its possible uses. We continue to maintain this software in the interest of developer education. Usage of this source code is not intended for production.

Download

Install

Include in your gradle

    compile 'network.xyo:sdk-xyo-android:3.1.38'

Include using Maven

    <dependency>
        <groupId>network.xyo</groupId>
        <artifactId>sdk-xyo-android</artifactId>
        <version>3.1.38</version>
        <type>pom</type>    
    </dependency>

Hardware recommendations

In order to test the full capabilities of this SDK, you will need an android smartphone (multiple devices are preferred but not necessary). We recommend using devices running at least Android 9. As the software matures, we anticipate that a wider range of android devices can utilize the SDK, but for integration testing in this early state, we recommend the devices below.

Recommended Android Devices

  • Google Pixel 2 or later
  • Samsung Galaxy 10 or later
  • OnePlus 7 or 8

When using Android Studio and an Android device to test BLE Client and Server be sure to enable permissions and add an initialization function in your MainActivity

AndroidManifest.xml

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />

MainActivity.kt

GlobalScope.launch {
  // place initialization function here for node build needed
  // you can look at the sample app for code example
}

As you are developing on the SDK, be sure to keep an eye out for updates, as they may include core and ble updates

How to use

One line is all it takes to start your node

    val node = XyoNodeBuilder().build(context)

For a more complex test, create a listener callback.

  // callback for node events
          val listener = object : XyoBoundWitnessTarget.Listener() {
              override fun boundWitnessCompleted(boundWitness: XyoBoundWitness?, error: String?) {
                  super.boundWitnessCompleted(boundWitness, error)

                  println("New bound witness!")
              }

              override fun boundWitnessStarted() {
                  super.boundWitnessStarted()

                  println("Bound witness started!")

              }
          }       

You can also configure to your specific roles.

          // build and configure the node
          val builder = XyoNodeBuilder()
          builder.setListener(listener)

          // create the node
          val context = getContextSomehow()
          val node = builder.build(context)

          // configure tcp
          val tcpNetwork = node.networks["tcpip"] ?: return
          tcpNetwork.client.autoBridge = true
          tcpNetwork.client.autoBoundWitness = true
          tcpNetwork.client.scan = false
          tcpNetwork.client.knownBridges = ["public key of bridge", "public key of bridge"]

          // configure ble
          val bleNetwork = node.networks["ble"] ?: return
          bleNetwork.client.autoBridge = true
          bleNetwork.client.autoBoundWitness = true
          bleNetwork.client.scan = false

You can also use a heuristic getter, here is an example to get GPS.

    (node.networks["ble"] as? XyoBleNetwork)?.client?.relayNode?.addHeuristic(
        "GPS",
        object: XyoHeuristicGetter {
            override fun getHeuristic(): XyoObjectStructure? {
                val locationManager = applicationContext.getSystemService(Context.LOCATION_SERVICE) as LocationManager

                if (ContextCompat.checkSelfPermission(applicationContext, android.Manifest.permission.ACCESS_FINE_LOCATION)
                    == PackageManager.PERMISSION_GRANTED) {
                    val lastLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER)

                    if (lastLocation != null) {
                        val encodedLat = ByteBuffer.allocate(8).putDouble(lastLocation.latitude).array()
                        val encodedLng = ByteBuffer.allocate(8).putDouble(lastLocation.longitude).array()
                        val lat = XyoObjectStructure.newInstance(XyoSchemas.LAT, encodedLat)
                        val lng = XyoObjectStructure.newInstance(XyoSchemas.LNG, encodedLng)

                        return XyoIterableStructure.createUntypedIterableObject(XyoSchemas.GPS, arrayOf(lat, lng))
                    }
                }
                return null
            }
        }
    )

Build an XYO Node

    val builder = XYONodeBuilder()

After calling the node builder, you can start the build

    val node = XyoNode()

    node = builder.build(this)

Once you have a build, you have access to properties to help you shape your node and what you want out of it.

    node.networks["this can be "ble" or "tcpip""]

After choosing the network, you have these properties available

Client

    // select the network
    val network = node.networks["network"]

    // a flag to tell the client to automatically bridge
    network.client.autoBridge

    // a flag to tell the client to automatically bound witness 
    network.client.autoBoundWitness

    // a flag to tell the client to automatically scan
    network.client.scan

Server

        // select the network 
        val network = node.networks["network"]

        // a flag to tell the server to automatically bridge
        network.server.autoBridge

        // a flag to tell the client to automatically listen for bridging
        network.server.listen
        ```

        These will allow your app to actively seek devices to bound witness with and bridge from the client to the server.

        You can also get payload data from the bound witness 

    ```kotlin
        node.listener.getPayloadData(target: XyoBoundWitnessTarget)

This will return a byteArray.

There are other properties from the client and server which you can find in the source code as well as a reference guide that we have prepared.

Architecture

This sdk is built on a client/server to ensure ease of understanding during development. (The client takes on "central" role, and the server the "peripheral"). This allows us to define roles with simplicity.

SDK-XYO-ANDROID TREE

  • XyoSDK

    • mutableList <XyoNode>

      • XyoNode(storage, networks)

        • listeners
          • boundWitnessTarget
      • XyoClient, XyoServer

        • Ble

          • context
          • relayNode
          • procedureCatalog
          • autoBridge
          • acceptBridging
          • autoBoundWitness
          • scan
        • TcpIp

          • relayNode
          • procedureCatalog
          • autoBridge
          • acceptBridging
          • autoBoundWitness

Android Sample App

Please refer to the xyo-android-sample for an exmple implementation for bound witness and bridging.

Install

To use the sample app to measure functionality

  • Launch Android Studio
  • Click on Open an existing Android Studio Project
  • Navigate to <path to the sdk-xyo-android>/xyo-android-sample in your file explorer

Once you open the sample in Android Studio it will go through the build process.

You can then run the app in a simulator of your choice or an Android device.

This sample app includes client bridging and bound witnessing with a BLE server listener.

Last updated on 5/15/2020
← SCSC LibrarySwift SDK →
  • Install
    • Recommended Android Devices
  • Build an XYO Node
    • Client
    • Server
  • Architecture
  • Android Sample App
    • Install

XYO | Developers

Copyright © 2020 XYO
DocsExplore AppProtocolSource Code
Community
GitHubTwitter