Skip to content

ntoll/RESTProvider

Repository files navigation

Android RESTProvider: A web services cursor interface

RESTProvider handles all the HTTP querying and caching. Users can seamlessly interface with any Web Service API which provides JSON or XML as a response. To query a RESTProvider in an activity a user need only specify an endpoint and then query an APIs RESTful functions.

  • Supports JSON & XML Web services
  • Handles HTTP querying & caching

RESTProvider is an implementation of functionality commonly used when dealing with web services in Android.

Example: Twitter stream as ListActivity

	
	public class TwitterFeedExample extends ListActivity {
		@Override public void onCreate(Bundle b) {
			super.onCreate(b);
			CPAsyncHandler g = new CPAsyncHandler(getContentResolver());
			g.startQuery(1, null, Uri.parse("content://novoda.rest.test.twitter"),
					null, "q=?", new String[] { "droidcon" }, null);
		}

		private class CPAsyncHandler extends AsyncQueryHandler {
			@Override
			protected void onQueryComplete(int token, Object cookie, Cursor c) {
				super.onQueryComplete(token, cookie, c);
				setListAdapter(new SimpleCursorAdapter(TwitterFeedExample.this,
						android.R.layout.simple_list_item_2, c, new String[] {
								"from_user", "text" }, new int[] {
								android.R.id.text1, android.R.id.text2 }));
			}
		
			public CPAsyncHandler(ContentResolver cr) {
				super(cr);
			}
		}
	}
	

Setup

The RESTProvider’s most recent version is only available in source but regular versions are available as jar files.
We recommend working from source as significant changes are still frequent at these early stages.
Download the latest source as an archive or checkout via git. The advantage of checking out via git is that updates can be quickly applied within your working environment using $git pull origin master. To checkout the latest source via git, within the directory you wish to download the project: git clone git://github.com/novoda/RESTProvider.git

In Eclipse:
File > New Android Project
Select Create project from existing source
For the location select: RESTProvider/RESTProvider
Dependant files needed on build path, add the following to RESTProvider/RESTProvider/lib

Refresh the directories in eclipse (F5 with the project selected)
All jars under ‘libs’ need to be added to the build path.
You can add each dependancy by right clicking the jar files under this directory and selecting Build Path > Add to Build Path.
You can now depend on this project as a build dependancy to use the RESTProvider in your project.

Demos

Follow these steps in Eclipse:
File > New Android Project
Select Create project from existing source
For the location select: RESTProvider/RESTProviderTest
All of the libraries under the RESTprovider ‘libs’ directory need to be added to the build path.
You can add each library by right clicking the jar files under this directory and selecting Build Path > Add to Build Path.

Dependant files needed on build path as Android cannot src the dependencies from the other project, add the followingto RESTProvider/RESTProviderTest/lib

You then need to add the RESTProvider’s src as a dependency of this project by right clicking Build Path > Link Src then selecting the directory of the RESTProvider’s src on your disk.
Note: Intrumentations cannot be run if the RESTProvider is included as src in the Demo project

Unit Tests are currently broken!

This is an experimental way of testing an android locally without deploying to the against an android emulated image using a n android.jar customly extended for testing. In order to provide a test framework, we use PowerMock as describe in the following page which I strongly recommend to follow and understand:
https://sites.google.com/site/androiddevtesting/

In Eclipse:
File > New Java Project
Select Create new project from existing source
For the location select: RESTProvider/RESTProviderLocalTest
Right click on Project dir
Build path > Configure Build Path
Add the RestProvider project as a dependency.
Dependant files needed on build path in the lib dir:

Exporting jar for use in project

In order for your dependant project to deploy correctly you will need to export the RESTProvider into your dependant project
as a jar. To do this:

Help improve the RESTProvider!

The RESTProvider project is for everyone to take advantage and will improve only with your feedback.
If you are using the RESTProvider or have issues then please let the community know.
This project is unsupported but contributors will try their best to reply to problems on mailing list.
http://groups.google.com/group/android-restprovider
Or you can raise issues on github.

About

REST Provider for Android

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published