sample-android-battery-data

Basic Android sample app using the Iobeam Java client library.

  • 所有者: iobeam/sample-android-battery-data
  • 平台:
  • 許可證: Apache License 2.0
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

Sample iobeam Android app

Using the iobeam Java Client Library

This is a basic sample app to illustrate how to send data to iobeam using the Java client library.

Here's what it looks like:

This app tracks the current battery level on your phone. Every time the battery level changes by more than 1%, the app uploads the timestamp and current level to iobeam.

All iobeam client library related code is in MainActivity.java

Before you start

First, you need a project_id, and project_token (with write-access) from a valid iobeam project. You can get these using our Command-line interface.

Next, find these lines in MainActivity.java, and update with your project_id and project_token. You also need to pick a device_id for your phone (must be globally unique and at least 16 characters long). E.g., "nerf-herder-1138".

/** Iobeam Parameters **/
private static final long PROJECT_ID = -1; // Your PROJECT_ID
private static final String PROJECT_TOKEN = null; // PROJECT_TOKEN (w/ write-access)
private static final String DEVICE_ID = null; // Specify your DEVICE_ID

(Note: We specify the device_id in this example for simplicity, but you can also allow the library to auto-generate the device_id for you. Please see our Java / Android client library docs for more.)

Compile, build, and run the app!

Where's the iobeam-specific code?

It's all in MainActivity.java.

Initialize the iobeam client library:

iobeam = new Iobeam.Builder(PROJECT_ID, PROJECT_TOKEN).saveIdToPath(path)
                .setDeviceId(DEVICE_ID).build();

Define the data schema:

String[] columns = new String[]{"battery_level", "temperature", "voltage"};
iobeamBatch = new DataBatch(columns);
iobeam.trackDataBatch(iobeamBatch);

Capture a data point:

Map<String, Object> values = new HashMap<String, Object>();
values.put("battery_level", currentBatteryLevel);
values.put("temperature", ((double)temperature/10));
values.put("voltage", voltage);
iobeamBatch.add(values);

Send to the Iobeam API:

iobeam.sendAsync();

That's it!

Enjoy!

主要指標

概覽
名稱與所有者iobeam/sample-android-battery-data
主編程語言Java
編程語言Java (語言數: 1)
平台
許可證Apache License 2.0
所有者活动
創建於2015-04-09 19:03:44
推送於2015-12-21 19:18:15
最后一次提交2015-12-21 11:18:15
發布數0
用户参与
星數7
關注者數3
派生數4
提交數20
已啟用問題?
問題數0
打開的問題數0
拉請求數3
打開的拉請求數0
關閉的拉請求數0
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?