Getting Started: New Open Source Android App
The Zypr open source Java API Access layer provides an abstraction to the Zypr server API, making it quick to create Zypr applications under Android.
This API library is open sourced, and is available on github.com/Zypr. All you need is the API .jar file and include it in your Android application build. You can also find the source for my sample application on github.com/Zypr/Zypr-Examples in android/ZyprAndroidExample-M01.
I’ve created a simple example Android application demonstrating basic Zypr user creation and authentication. The application flow contains 3 activities: a Login screen, a User Info screen shown when a user is logged in, and a Create User screen. For this simple example, the user info screen will only show the token returned from logging in and the generated device id.
Step 0 — Acquiring and inserting your own Developer API key
You will need your own API key to run the example. Go to developer.zypr.net and login or create a new account. Then select ‘Create New Application’. Follow the instructions and you will get an API key that you can use for this sample app. You will need to put this API key in res/values/keys.xml replacing the text REPLACEWITHMYOWNAPIKEY with your valid API key. With this change in place, you should be able to build and run this sample application.
Step 1 — Creating a User
To create a new user we use the createUser() API call in Auth_create_userActivity.java which takes the new user’s name and password as parameters. When you press the create user button we call the library like this:
API.getInstance().getAuth().createUser(username, password, password_confirm);
This will request the user be created on the server. If the call fails, we generate an error message and let the user try again.
Step 2 — Logging In
In Auth_loginActivity.java we have a button that when we press will actuate the login() API to attempt to authenticate the username and password you enter as a valid Zypr user:
API.getInstance().getAuth().login(username, password);
Step 3 — Logging out
Once you’ve logged in a user, a simple screen is presented that displays the API token returned by the server indicating a valid, authenticated session has begun.
When you select the logout button the application notifies the server via this API call:
API.getInstance().getAuth().logout();
Now that you have the basic user authentication in place, you can now proceed to add your own custom features to the application or integrate Zypr into your own existing project.
Comments are closed.

