sample-android-battery-data

Basic Android sample app using the Iobeam Java client library.

  • Owner: iobeam/sample-android-battery-data
  • Platform:
  • License:: Apache License 2.0
  • Category::
  • Topic:
  • Like:
    0
      Compare:

Github stars Tracking Chart

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!

Main metrics

Overview
Name With Owneriobeam/sample-android-battery-data
Primary LanguageJava
Program languageJava (Language Count: 1)
Platform
License:Apache License 2.0
所有者活动
Created At2015-04-09 19:03:44
Pushed At2015-12-21 19:18:15
Last Commit At2015-12-21 11:18:15
Release Count0
用户参与
Stargazers Count7
Watchers Count3
Fork Count4
Commits Count20
Has Issues Enabled
Issues Count0
Issue Open Count0
Pull Requests Count3
Pull Requests Open Count0
Pull Requests Close Count0
项目设置
Has Wiki Enabled
Is Archived
Is Fork
Is Locked
Is Mirror
Is Private