android apiclient,asddr

Android Client API

Nabto ApS client API for Android.

Nabto provides a full communication infrastructure to allow direct, encrypted communication between clients and IoT devices - the Nabto communication platform. The platform supports direct peer-to-peer connectivity through NAT traversal.

Installation

The simplest way to use the Nabto client API for Android is by including the Apache Maven package from JCenter by adding the following to your project's build.gradle:

repositories {

jcenter()

}

dependencies {

compile 'com.nabto.android:nabto-api:1.4.0'

}

Note about version identifiers

The version information returned by nabto.versionString is the core Nabto Client SDK version - not the version of the Android wrapper (the component described in this document). See the release notes for the individual Android wrapper version to see the Nabto Client SDK core version wrapped.

Build

In case you want to build the Android Client API library yourself, follow these steps:

1. Download native libraries and resources

Download the Nabto Client SDK resources and native libraries from downloads.nabto.com, and copy them to android-client-api/src/main/ in order to get the following structure:

src

└── main

├── assets

│   └── share

│   └── nabto

│   ├── configuration

│   ├── roots

│   ├── schemas

│   ├── skins

│   └── users

├── java

├── jniLibs

│   ├── armeabi

│   │   └── libnabto_client_api_jni.so

│   ├── armeabi-v7a

│   │   └── libnabto_client_api_jni.so

│   └── x86

│      └── libnabto_client_api_jni.so

└── res

2. Run tests (optional)

# ./test.sh

For more details see section "Test".

3. Build

# gradle build -x test

4. Use the AAR library

Use the generated AAR library, found in android-client-api/build/outputs/aar/, in your projects.

Usage Example

The simplest possible example of using the Android client API:

import com.nabto.api.*;

NabtoClient client = new NabtoClient(context);

// Start Nabto and login as guest

if(client.init("guest", "12345") == NabtoStatus.OK) {

// Make a Nabto request to a device

String url = "nabto://demo.nabto.net/wind_speed.json?";

UrlResult result = client.fetchUrl(url);

if(result.getStatus() == NabtoStatus.OK) {

// Get the response

String response = new String(result.getResult());

}

}

// Stop Nabto

client.pause();

However, the NabtoClient does not support streaming and tunneling. Use the NabtoApi class for a full featured API. Same example:

NabtoApi api = new NabtoApi(new NabtoAndroidAssetManager(this));

// Start Nabto

api.startup();

// Login as guest

Session session = api.openSession("guest", "123456");

if(session.getStatus() == NabtoStatus.OK) {

// Make a Nabto request to a device

String url = "nabto://demo.nabto.net/wind_speed.json?";

UrlResult result = api.fetchUrl(url, session);

if(result.getStatus() == NabtoStatus.OK) {

// Get the response

String response = new String(result.getResult());

}

}

// Stop Nabto

api.closeSession(session);

api.shutdown();

Test

The Android Client API is tested using a stubbed version of the Nabto Client SDK to exercise the JNI layer (used in NabtoCApiWrapperTest.java) and a mocked API at the Java level to exercise the higher level Java wrapper (used in NabtoApiTest.java). The source files of the stub are located in /home/cs/nabto/android-client-api/src/test/jniLibs/. A bash script is provided to automate building the stub and executing the tests.

Important: Make sure $JAVA_HOME is set.

You have two options:

1. Test the whole Android Client API (default)

# ./test.sh android

2. Test the Java wrapper only

# ./test.sh java

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值