basics

How to display an AlertDialog in your Android application

SDK Version: 
M3

Here is an example of an applacation, that illustrates how you can create a simple AlertDialog. The dialog can display maximum three buttons.



How to play video and audio on Android

SDK Version: 
M3

There is more than one way, to play media files on an Android phone, let me show you two of them.

picture

Audio:
MediaPlayer is the easier way, if you just want to play an audio file in the background, somewhere in an appliaction. There are no ui controls here, but of course you can use MediaPlayer.stop(), play(), seekTo() ,etc. Just bind the needed functions to a button, gesture, or event. As you can see, it also throws a lot of exceptions, which you need to catch.

  1.  public void audioPlayer(String path, String fileName){
  2.     //set up MediaPlayer    
  3.     MediaPlayer mp = new MediaPlayer();
  4.  
  5.     try {
  6.         mp.setDataSource(path+"/"+fileName);
  7.     } catch (IllegalArgumentException e) {
  8.         // TODO Auto-generated catch block
  9.         e.printStackTrace();
  10.     } catch (IllegalStateException e) {

How to make Tabs UI with icons

SDK Version: 
M3

So here's how it's going to be look like:

Your class has to extend TabActivity:

  1. public class YourClass extends TabActivity {
  2. ...
  3. ...
  4. }

After that, here's how to configure a Tab:
1. Create a LinearLayout in your main.xml, with the id: "TabOne"
2. Paste these lines after onCreate() :

Data Storage tutorial, basic samples are included

SDK Version: 
M3

    Data Storage Methods

  • Preferences
  • Preferences is a lightweight mechanism to store and retrieve key-value pairs of primitive data types.
     
  • Files
  • You can store your data in files on your mobile phone, or in a removable storage medium.
     
  • Databases
  • Android Api supports SQLite databases. All databases, SQLite and others, are stored on the device in /data/data/package_name/databases.
     
  • Network
  • You can also use the Internet to store and receive data, whether it's an SQLite database, or just a simple textfile.

Introducing the Android Emulator, managing Android Virtual Devices (AVD)

SDK Version: 
M3
The emulator available in the Android SDK is not just a tool that allows you to easily test applications without having to install it to a real device, or even having one. With the proper configuration it is possible to test situations which are hardly reproduced on a physical one.
 
After installing the android plugin and SDK in eclipse an icon is automatically placed on the toolbar to quickly access the Android SDK and AVD (Android Virtual Device) manager.
 
eclipse

You can create multiple AVDs with different parameters:

sdk

How to set up Eclipse with Android SDK on Ubuntu linux 9.04/9.10 (updated)

SDK Version: 
M3

In my first tutorial i will show you how to set up Eclipse 3.5 with Android Development Tools (ADT) on Ubuntu 9.04.

Before we can install the Android SDK, we must install Java. First we open a new terminal window (Applications > Accessories > Terminal).

To install Java, type:

sudo apt-get install sun-java6-bin 

If you are on a x86_64 system, you also must install ia32-libs:
 

sudo apt-get install ia32-libs

For Ubuntu 9.10 users:

In my first tutorial i will show you how to set up Eclipse 3.5 with Android Development Tools (ADT) on Ubuntu 9.04.

Before we can install the Android SDK, we must install Java. First we open a new terminal window (Applications > Accessories > Terminal).

To install Java, type:

sudo apt-get install sun-java6-bin 

If you are on a x86_64 system, you also must install ia32-libs:
 

sudo apt-get install ia32-libs

For Ubuntu 9.10 users:

Install eclipse from apt-sources, so open a terminal, then:

sudo apt-get install eclipse

How to set location on emulator

SDK Version: 
M3

emulatorYou have two options if you would like to set the location on the emulator. For both options, you start with starting the emulator first.

Option 1: using DDMS

  • go to your android/tools directory, and launch the DDMS tool
  • select the Emulator Control Tab
  • fill the Location Controls fields with the longitude and latitude values
  • press the Send button

Option 2: using telnet

Custom View - HorizontalSlider

SDK Version: 
M5

In this tutorial we'll create a custom View called HorizontalSlider based on ProgressBar. This slider will allow the user to move the slider back and forth on the screen and get notified when this happens.

Using threads and ProgressDialog

SDK Version: 
M5

This example shows you how to properly use a thread to do work while displaying an indeterminate ProgressDialog.

Syndicate content