Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Android code to post data to that Kinesis Stream
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
import com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.KinesisRecorder;
File directory = getApplicationContext().getCacheDir();
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(getApplicationContext(), "Identity pool ID", Regions.US_WEST_2);
KinesisRecorder kinesisRecorder = new KinesisRecorder(directory, Regions.US_WEST_2, credentialsProvider);
String kinesisStreamName = "test2-kinesis-data-stream";
JSONObject json = new JSONObject();
try {
json.accumulate("rpm", vehicleStats.getRpm());
json.accumulate("speed", vehicleStats.getSpeed());
json.accumulate("fuel", vehicleStats.getFuel());
json.accumulate("distance", vehicleStats.getDistance());
json.accumulate("vin", vehicleStats.getVin());
json.accumulate("dtc", vehicleStats.getDtc());
json.accumulate("timestamp", vehicleStats.getTimestamp());
kinesisRecorder.saveRecord(json.toString(), kinesisStreamName);
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... v) {
try {
} catch (AmazonClientException ace) {
Log.e(TAG, "Error = " + ace.getMessage());
return null;
} catch (Exception e) {
Log.e(TAG, "Error = " + e.getMessage());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.