This is an Android remote (AIDL) service for accessing Xively API asynchronously.
The implementation can be found under service
subdirectory.
An example of the consumer of this service can be found under demo
subdirectory.
It uses Android's URLConnection
for handling HTTP requests and have no external dependencies.
It is deliberately designed to be very lightweight. For a fully featured HTTP client library, check out our Java library.
It currently supports API9 (Gingerbread) to API17 (Jelly Bean).
This library is Open Source, under the BSD 3-Clause.
Copyright © 2003-2013 LogMeIn, Inc. All rights reserved.
See LICENSE.md
for full text of the license.
You will need to set your API key and feed ID in these files:
test/src/com/xively/android/service/test/HttpServiceTest.java
demo/src/com/xively/android/consumer/DemoActivity.java
The consumer of this service will be able to access Xively API via all methods defined in the IHttpService.aidl
.
As seen from the demo project, the following files must be present in the consumer as per AIDL service specified by Android:
com.xively.android.service.Response.java
com.xively.android.service.IHttpService.aidl
com.xively.android.service.Response.aidl
The name of the intent this service listens to is com.xively.android.service.HttpService
, as per the AndroidManifest.xml
:
<service android:name="com.xively.android.service.HttpService" >
<intent-filter>
<action android:name="com.xively.android.service.HttpService" />
</intent-filter>
</service>
Multiple client apps can connect to this service if the include the above snippet on AndroidManifest.xml
.
RESTful requests to Xively API are managed by HttpService
when invoked by an intent.
The service uses AsyncTask
to make the request.
The response is expected to return from AsyncTask
within the time as specified in HttpService.DEFAULT_TIMEOUT
.
An exception will be thrown otherwise.
All exception thrown out of this library is RemoteException
, as prescribed by AIDL specification.
For compatibility with Android version before API15, any caught exception in this service will be returned as a response with its status that represents an exception condition (HTTPService.HTTP_SERVICE_ERROR
).
The response from the service can be retrieved as string:
response.getContent()
which the client can then easily turned into a JsonObject
by:
new JSONObject(response.getContent())