Run Android as Kiosk or Single Application Mode

If you are planning to roll out an android application on a tablet for public use. Then running it as a kiosk mode is preferred, we can also call SINGLE APPLICATION MODE.

To achieve it there are couple of ways:

  • Custom build ROM according to your needs. I have not tried my hands over it, as it seems to be time intensive.
  • SureLock from 42gears. It works great but one need to buy License (Single $49.99)
  • Code tweak. It’s not fool proof but can be helpful to run Android in Single Application mode

 

We will talk about “CODE TWEAK” method and guide how to achieve the same. Inside your application code make following changes

Manifest file:

1. Add this to your main activity . This will launch your application when home button is pressed.

<intent-filter>
<action android:name=”android.intent.action.MAIN” />
<category android:name=”android.intent.category.HOME” />
<category android:name=”android.intent.category.DEFAULT” />
</intent-filter>

2. Auto-start your application on Boot by listening to by listening to the android.intent.action.BOOT_COMPLETED. Add this line to your Manifest file

<uses-permission android:name=”android.permission.RECEIVE_BOOT_COMPLETED” />

 

3.  Inside the main Application tag. Add this receiver code like you add a new activity

<receiver android:name=”com.example.android.MyBroastcastReceiver”>
    <intent-filter>
        <action android:name=”android.intent.action.BOOT_COMPLETED” />
    </intent-filter>
</receiver>
 

4. Add a file to your “src/com/example/android/MyBroadcastReceiver.java” and add these lines

package com.example.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
 
public class MyBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Intent startServiceIntent = new Intent(context, <MAIN>.class);
        context.startService(startServiceIntent);
    }
}

 

Edit <MAIN> to the activity you wish to auto-boot.

 

5. Reboot your tablet/device and it should run in Auto-Boot  Single application mode. It may prompt for default home option to select between “Launcher” and “Your Application”. Select your application and tick the checkbox to make it default selection.

 

One can now browse only device settings and run your application. To exit and run Android Launcher, go to Settings->apps->your application and “Clear Defaults”. Pressing the home button will again prompt for default  home option select Launcher this time and you can access the Android default launcher. I have tested on Android 4.0.3 and it’s working smooth.

 

Ideas/suggestions are welcome.

Smartphone Native Application using Ruby in 30 min

Building a Smartphone (Android, iPhone, BlackBerry etc) app using ruby

Google Android
iPhone Logo
BlackBerry Logo


RhoMobile Framework


Rhodes

Rhodes is an open source framework to rapidly build NATIVE apps for all major smartphone operating systems (iPhone, Windows Mobile, RIM, Symbian and Android). These are true native device applications (NOT mobile web apps) which work with synchronized local data and take advantage of device capabilities such as GPS, PIM contacts and camera.

Yeah! Its in Ruby 🙂

  • support for ALL smartphones
  • synchronized offline data
  • a Model View Controller (MVC) framework
  • an Object Relational Manager (ORM) to avoid direct SQL coding
  • the mobile Ruby
  • a hosted development service
  • scaffolding to quickly build the app

Setup (Android)

  • gem install rhodes
  • Java JDK latest version is needed for Android. Make sure its installed. Test by typing $javac -version in your terminal
  • Download Android SDK (for linuxMac OSWindows) and extract at a convenient location.
  • Change in your ~/.bash_profile(Mac) and ~/.bashrc(Linux) to add
    export PATH=/path-to-android/tools:$PATH
    export ANDROID_HOME=/path-to-android
  • typing $android in the terminal shall start Android SDK and AVD Manager
  • once ACD manager started install the latest packages under “Available packages”, it will take a while to install
  • Once installed they will list under “Installed Packages”
  • else installation follow these instructions to install Android SDK starter packages, and change the PATH environment variable for sure
  • Download and install Android NDK (Win, Mac OS, Linux) and export your path same as above

Setting up rhodes
Now we need to link our rhodes installation to the SDK and eclipse.
$rhodes-setup
You’ll be prompted with questions – my answers are below:
  • JDK path: /Library/Java/Home
  • Android SDK path: /opt/androidSDK/
  • Android NDK path: /opt/androidNDK/
  • the remainder of the questions related to Windows and Blackberry: (left blank)

HelloWorld Program

rhogen app HelloWorld

cd HelloWorld

rake -T  (will list all the rake tasks for all supported smartphones)

rake run:android (it will build, install and launch the HelloWorld Program)

Of course it will be blank and its just the start. Go to launcher you will be able to see your HelloWorld application with rhodes default icon.

My Contacts

This is fine, but what about ruby and MVC framework? Open your latest HelloWorld in your favorite editor(textmate etc). You will find an “app”, “app=>helpers” folder much like rails “rhoconfig.txt” => configuration settings

$ rhogen model Contact name, email, phone

Generating with model generator:

[ADDED]  app/Contact/index.erb

[ADDED]  app/Contact/edit.erb

[ADDED]  app/Contact/new.erb

[ADDED]  app/Contact/show.erb

[ADDED]  app/Contact/index.bb.erb

[ADDED]  app/Contact/edit.bb.erb

[ADDED]  app/Contact/new.bb.erb

[ADDED]  app/Contact/show.bb.erb

[ADDED]  app/Contact/contact_controller.rb

[ADDED]  app/Contact/contact.rb

[ADDED]  app/test/contact_spec.rb

You can see the controller, model and view files similar to Rails frame work.

Change the

start_path = ‘/app/Contact’ (in rhoconfig.txt)

$ rake run:android

Your application will relaunch and you can click “new” button to add new contacts and edit and delete them. So basic CRUD functionality is available much like rails and ready to go.

I hope you will find this ready to go tutorial very helpful to start of your application on any smartphone using Rhodes framework.

Stay tuned for more!