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?
已存档?
是复刻?
已锁定?
是镜像?
是私有?