Documentation : Android Simple Tutorial

This is a simple example where we describe how to sync blog entries between devices. To develop this case you should:

  • design simple model with two fields
  • deploy our simple app on test enviroment
  • configure your app on the mobile
  • use our API to sync designed model between devices

Create your App

Start working with the Mobeelizer. Create your FREE account.

Let's design your first App. Open the Mobeelizer App Designer and login with your account. Then, press CREATE NEW APPLICATION button and insert it's name blog.

Design your App Schema

In your applications designer panel enter Models section on the left. Then create new model Blog and add two text fields to it.

Deploy your App into the test environment

Deploy your app into the test environment using DEPLOY TO TEST button.

Get the Mobeelizer SDK

Prepare plain Android application, get the Mobeelizer SDK and put it into "libs" directory.

Get your App definition

Download App definition and save it into "assets" directory as "application.xml".

Confligure your App

Open "AndroidManifest.xml" and configure your App.

<?xml version="1.0" encoding="utf-8"?>

<manifest ...>
	<uses-permission android:name="android.permission.INTERNET" />
	<uses-permission android:name="android.permission.READ_PHONE_STATE" />
	<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
	<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
	<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
	<application ... android:name="com.mobeelizer.mobile.android.Mobeelizer">
		...
		<service android:name="com.mobeelizer.mobile.android.MobeelizerSyncService" />
		<meta-data android:name="MOBEELIZER_DEVICE" android:value="mobile" />
		<meta-data android:name="MOBEELIZER_PACKAGE" android:value="com.yourcompany.yourapp.schema" />
		<meta-data android:name="MOBEELIZER_DEVELOPMENT_ROLE" android:value="users-mobile" />
		<meta-data android:name="MOBEELIZER_MODE" android:value="test" />
	</application>
</manifest>

Want to know what these metadata mean? Check the documentation for detailed description.

Create Blog object

Create class "Blog" in "com.yourcompany.yourapp.schema" package.

package com.yourcompany.yourapp.schema;

public class Blog {

	private String guid;
	private String title;
	private String content;

	public String getGuid() {
		return guid;
	}
	public void setGuid(final String guid) {
		this.guid = guid;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(final String title) {
		this.title = title;
	}
	public String getContent() {
		return content;
	}
	public void setContent(final String content) {
		this.content = content;
	}
}

Looking for information how to convert schema definition into objects? Check the documentation for detailed description.

Use the Mobeelizer SDK

Before any object will be stored the device must be authenticated.

 

MobeelizerOperationError error = Mobeelizer.login("user", "password");
 
if(error != null) {
  // login error, more info in error.getMessage()
}

Once you are logged in you have access to the database.

 

MobeelizerDatabase database = Mobeelizer.getDatabase();

 

Let's create a Blog object and store it in the database.

 

Blog blog = new Blog();
blog.setTitle("First entry");
blog.setContent("I'm proud to announce that my first application is working properly.");
MobeelizerErrors errors = database.save(blog);

So we have stored our very first object. Let's check it.

boolean exists = database.exists(Blog.class, blog.getGuid()); // => true
long count = database.count(Blog.class); // => 1
Blog blogFromDatabase = database.get(Blog.class, blog.getGuid()); // => blogFromDatabase != null

Is our Blog entry shared in the cloud? It will be soon.

MobeelizerOperationError error = Mobeelizer.sync();

if(error != null) {
  // sync error, more info in error.getMessage()
}

Remember to logout before closing the application.

 

Mobeelizer.logout();

 

Run the App on the device

That's all. Compile your App and deploy it to the device. Then create a blog entry and sync it with the cloud. It will be visible by other devices.

Attachments:

insert_application_name.png (image/png)
download_android_SDK.png (image/png)
a52e2bab22d6ce7f9ea10d854b8ea561.png (image/png)
newModel.png (image/png)
newField1.png (image/png)
newField2.png (image/png)
deploy.png (image/png)