Skip to content

Latest commit

History

History

README.md

Android SDK

Android client library to assist with using the Watson Developer Cloud services, a collection of REST APIs and SDKs that use cognitive computing to solve complex problems.

Installation

Gradle

'com.ibm.watson.developer_cloud:android-sdk:0.2.0'

AAR

Download the aar with dependencies from the Releases page.

Examples

This SDK is built for use with the java-sdk. The examples below are specific for Android as they use the Microphone and Speaker; for actual services refer to the java-sdk.

More examples here.

Microphone Input Stream

Convenience function for creating an InputStream from device microphone. You can record raw PCM data or data encoded using the ogg codec.

// record PCM dataInputStreammyInputStream = newMicrophoneInputStream();
// record PCM data and encode it with the ogg codecInputStreammyOggStream = newMicrophoneInputStream(true);

An example using a Watson Developer Cloud service would look like

speechService.recognizeUsingWebSocket(newMicrophoneInputStream(),
getRecognizeOptions(), newBaseRecognizeCallback() {
@OverridepublicvoidonTranscription(SpeechResultsspeechResults){
Stringtext = speechResults.getResults().get(0).getAlternatives().get(0).getTranscript();
System.out.println(text);
}
@OverridepublicvoidonError(Exceptione) {
}
@OverridepublicvoidonDisconnected() {
}
});

StreamPlayer

Provides the ability to directly play an InputStream

StreamPlayerplayer = newStreamPlayer();
player.playStream(yourInputStream);

CameraHelper

Provides simple camera access within an activity.

CameraHelpercameraHelper = newCameraHelper(this);
cameraHelper.dispatchTakePictureIntent();
@OverrideprotectedvoidonActivityResult(intrequestCode, intresultCode, Intentdata) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CameraHelper.REQUEST_IMAGE_CAPTURE) {
System.out.println(cameraHelper.getFile(resultCode));
}
}

GalleryHelper

Like the CameraHelper, but allows for selection of images already on the device.

To open the gallery:

GalleryHelpergalleryHelper = newGalleryHelper(this);
galleryHelper.dispatchGalleryIntent();
@OverrideprotectedvoidonActivityResult(intrequestCode, intresultCode, Intentdata) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GalleryHelper.PICK_IMAGE_REQUEST) {
System.out.println(galleryHelper.getFile(resultCode, data));
}
}

Testing

Testing in this SDK is accomplished with Espresso.

To run the tests, in Android Studio:

Within the example package, right-click the androidTest/java folder and click Run 'All Tests'.

Build + Test

Use Gradle (version 2.x) to build and test the project you can use

Gradle:

$ cd android-sdk
$ gradle test# run tests