Data Storage Schemes in Android-Shared preferences (Setting Font Size)

To Setting Dynamic Fonts Size in Android Activity Use “Shared Preferences”

1. Create a project SharedPreference and add the bellow code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

        android:layout_height="wrap_content" />

        android:text="@string/hello" />

        android:layout_height="wrap_content" />

        android:layout_height="wrap_content" />


package com.jetbrain.nazim.sharedpreferences;
//[changeable as your project package]

import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Toast;

public class SharedPreferencesActivity extends Activity {

    private SharedPreferences prefs;
    private String prefName = "MyPref";
    private EditText editText;
    private SeekBar seekBar;
    private Button btn;

    private static final String FONT_SIZE_KEY = "fontsize";
    private static final String TEXT_VALUE_KEY = "textvalue";

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        editText = (EditText) findViewById(;
        seekBar = (SeekBar) findViewById(;
        btn = (Button) findViewById(;

        btn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {

                //---get the SharedPreferences object---
                //prefs = getSharedPreferences(prefName, MODE_PRIVATE);
                prefs = getPreferences(MODE_PRIVATE);

                SharedPreferences.Editor editor = prefs.edit();

                //---save the values in the EditText view to preferences---
                editor.putFloat(FONT_SIZE_KEY, editText.getTextSize());
                editor.putString(TEXT_VALUE_KEY, editText.getText().toString());

                //---saves the values---

                //---display file saved message---
                        "Font size saved successfully!"+editText.getTextSize(),

        //---load the SharedPreferences object---
        //SharedPreferences prefs = getSharedPreferences(prefName, MODE_PRIVATE);
        prefs = getPreferences(MODE_PRIVATE);

        //---set the TextView font size to the previously saved values---
        float fontSize = prefs.getFloat(FONT_SIZE_KEY, 12);

        //---init the SeekBar and EditText---
        seekBar.setProgress((int) fontSize);
        editText.setText(prefs.getString(TEXT_VALUE_KEY, ""));

        seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
            public void onStopTrackingTouch(SeekBar seekBar) {

            public void onStartTrackingTouch(SeekBar seekBar) {

            public void onProgressChanged(SeekBar seekBar, int progress,
                                          boolean fromUser) {
                //---change the font size of the EditText---

now run your project


Android spinner (drop down list) example

Original Post:

In Android, you can use “android.widget.Spinner” class to render a dropdown box selection list.

Spinner is a widget similar to a drop-down list for selecting items.

In this tutorial, we show you how to do the following tasks :

  1. Render a Spinner in XML, and load the selection items via XML file also.
  2. Render another Spinner in XML, and load the selection items via code dynamically.
  3. Attach a listener on Spinner, fire when user select a value in Spinner.
  4. Render and attach a listener on a normal button, fire when user click on it, and it will display selected value of Spinner.

P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.

1. List of Items in Spinner

Open “res/values/strings.xml” file, define the list of items that will display in Spinner (dropdown list).

File : res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
    <string name="app_name">MyAndroidApp</string>
    <string name="country_prompt">Choose a country</string>
    <string-array name="country_arrays">
        <item>United States</item>
        <item>New Zealand</item>

2. Spinner (DropDown List)

Open “res/layout/main.xml” file, add two spinner components and a button.

  1. In “spinner1″, the “android:entries” represents the selection items in spinner.
  2. In “spinner2″, the selection items will be defined in code later.

File : res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >
        android:prompt="@string/country_prompt" />
        android:layout_height="wrap_content" />
        android:text="Submit" />

3. Code Code

Read the code and also code’s comment, it should be self-explanatory.

File :

import java.util.ArrayList;
import java.util.List;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.Toast;
public class MyAndroidAppActivity extends Activity {
  private Spinner spinner1, spinner2;
  private Button btnSubmit;
  public void onCreate(Bundle savedInstanceState) {
  // add items into spinner dynamically
  public void addItemsOnSpinner2() {
	spinner2 = (Spinner) findViewById(;
	List<String> list = new ArrayList<String>();
	list.add("list 1");
	list.add("list 2");
	list.add("list 3");
	ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
		android.R.layout.simple_spinner_item, list);
  public void addListenerOnSpinnerItemSelection() {
	spinner1 = (Spinner) findViewById(;
  // get the selected dropdown list value
  public void addListenerOnButton() {
	spinner1 = (Spinner) findViewById(;
	spinner2 = (Spinner) findViewById(;
	btnSubmit = (Button) findViewById(;
	btnSubmit.setOnClickListener(new OnClickListener() {
	  public void onClick(View v) {
		"OnClickListener : " + 
                "\nSpinner 1 : "+ String.valueOf(
spinner1.getSelectedItem()) + 
                "\nSpinner 2 : "+ String.valueOf(

File :

import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Toast;
public class CustomOnItemSelectedListener implements 
OnItemSelectedListener {
  public void onItemSelected(AdapterView<?> parent, View view, 
int pos,long id) {
		"OnItemSelectedListener : " + 
  public void onNothingSelected(AdapterView<?> arg0) {
	// TODO Auto-generated method stub

4. Demo

Run the application.

1. Result, two spinners are displayed :

android spinner demo1
android spinner demo2

2. Select “France” from spinner1, item selection listener is fired :

android spinner demo3

3. Select “list2″ from spinner2, and click on the submit button :

android spinner demo4

Download Source Code

How To Download Apk File From Google Play to PC ?

Method 1


1. Go to
2. In the page, Copy paste the Google Play URL of the app or game in the textbox and hit Generate Download Link.

The link generation may take up to 5 minute depends by the size of the apk….wait till it returns the download link.

3. Finally, Click on Click here to download com.example.appname now button.

That’s it…now the download will start automatically.

Method 2


1. Download the latest version of APK Downloader extension from the developer website.
2. Open chrome://extensions/ and drag the downloaded file in to that page.
3. Click Add on the confirm extension install.
4. After Install..Click Options link below APK Downloader extension.

apk downloader chrome options

5. It will open a new chrome tab to enter login information. Where enter the fields below.

apk downloader chrome login info

Email – use the Gmail id which should be the primary Gmail id in your device.
Password – dummy Gmail’s password
Android Device ID – enter your device id ( to get device ID dial *#*#8255#*#* or use GTalk Service app from Google Play )

android device id

6. Click Login…Done ..( You can set the Country and SIM operator by clicking show advancedsettings )
7. Now go to Google Play and open the App or Game you want to download.
8. Finally click on the APK Downloader icon in the right side of the address bar.

apk downloader icon address bar

That’s it…!

Method 3


1. Download and install JRE (Java Run time environment ) – Download
(Skip this step if you all ready installed JRE)
2. Download and Extract Latest version Real APK Leecher – Download
3. Open Real APK Leecher.exe
4. Now it will ask you to enter Email , Password , Device id ,default country etc..enter it same as method 1’s 5th step…and click Save.

That’s it the next screen you can search and download the desired apps and games.

How to Connect Internet From PC or Laptop to Android Mobile Phone: Connect Internet from Laptop to Android mobile through Wi-Fi

What is Tethering?

Tethering is a process of sharing your phones mobile data with other devices like Laptop, Tablet etc.

Reverse Tethering is exactly opposite to Tethering i.e. the mobile device uses computer or laptop to receives internet data.

The transfer of internet data from PC to Android mobile can be done in two ways

  1. Wi-Fi
  2. USB

Connect Internet from Laptop to Android mobile through Wi-Fi

This method require

1) A Laptop with Wi-Fi Enabled and Internet Connection

2) An Android mobile.

3) Software called Connectify.

First Download Connectify Software and install it on your Laptop. This software is available for free.

Connectify software makes your PC into Wi-Fi Hotspot and shares your Internet Connection.

Now Enable Wi-Fi on your Laptop

Open the installed Connectify software

Since you are using the software for the first time you have to make some settings.

In the settings tab you have to enter the Hotspot name and password in the next box.

In the Dropdown choose the network you wanted to share i.e. the current internet connection you are using.

Internet from Laptop to Android mobile

Now you are almost done turn on Wi-Fi on your Android mobile and connect to the Hotspot you have setup.

Connect Internet from Laptop to Android mobile through USB

This method require

1) Computer with internet connection

2) Android Mobile Phone with USB data cable

3) Easy Tether Lite App

4) Easy Tether Setup

This method doesn’t require rooting of your Android mobile.

First Download Easy tether setup and install it on your computer.

Go to the Google play store Download Easy tether lite app and install it on your android mobile.

Open easy tether lite app on your mobile, in the settings choose USB

Internet from Laptop to Android mobile through USB

Right click on the easy Tether icon present in the notification area and choose connect via USB

Internet from Laptop to Android mobile

Now open Network and sharing settings in your computer and share your internet connection with Easy Tether Network Adapter.

Now it’s done, you can use internet on your Android mobile.

Install Android development environment on Windows 7

About a year ago I wrote a blog post about how to get started with Android development on Windows. At lot of new versions has been released since then, even though the basic packages needed are the same. This is a recap of what to download and how to set it up in order to develop Android applications on Windows 7 (64-bit).

My background is primarily in Microsoft.NET and Microsoft Visual Studio, so it did feel a little different when I first entered the world of Java and Android development. But once you get past those initial hurdles, it isn’t as different as you first might have thought.

These are the steps to get started with Android development on Windows. Should work on any Windows version, but I’m using Windows 7 64-bit.

  1. Download and install Java SDK.
  2. Download and unzip Android SDK.
  3. Run “SDK Manager” from Android SDK to download the platform versions.
  4. Download and unzip Eclipse.
  5. Install the Android plugin for Eclipse and point to the Android SDK.

You can read the instructions here, or watch a screencast I made describing the same procedure:

Download and install Java SDK

You’ll find the Java SDK here:

Click the “Download JDK” button and choose the Windows version you have from the Platform combobox. You don’t have to register to download. I ended up downloading a file called “jdk-6u22-windows-x64.exe”. Run it and accept all defaults to complete the installation.

Download and unzip Android SDK

The Android SDK doesn’t have an install executable, but rather a zip file and a utility called “SDK Manager.exe”. Begin by downloading the sdk from here:

Unzip the file to any location you want. I put it in “C:\Android\SDK”. Inside that folder, you’ll find the executable “SDK Manager.exe”. Run it. Every time you run that application, it will look for updates to anything you’ve downloaded previously with the same tool. The first time it will default to download all platform versions of Android except the Google specific ones. I’d recommend selecting Cancel at this initial update dialog, and then download what you need from “Available packages” instead.

The Android platform has been released in several versions since its initial offering of version 1.0. Every Android application will require a specific version, but will of course work on all subsequent versions too (at least in a perfect world). Today, I recommend that you target version 2.1 as the least common denominator. But note that there might still be users and phones of at least version 1.6 that might be of interest to you. Anyway, this means that I would download version 2.1 and the latest version 2.2. They don’t really take up that much disk space (maybe ~100MB per version?), so it won’t hurt you too much to download them all either.

Also, every Android platform version comes in a “Android plain vanilla” variant and a “Google APIs” variant. The only differences between those two are that “Google APIs” variant will include the ability to use Google Maps component and some other Google specific APIs that some Android devices might not support. I found this naming to be a little strange at first, but note that “Google APIs” includes everything in “Android plain vanilla” too.

The point is that if your application doesn’t need things such as Google Map component, you will be targeting more devices if you choose to develop for “Android plain vanilla”. As far as I know, all commonly sold Android phones support the Google APIs and it is only simpler media players and maybe cheap tablets that might not have chosen to support Google APIs (since I assume the manufacturer pays licensing fees to Google for that).

Run “SDK Manager” from Android SDK to download the platform versions

So, running “SDK Manager”, cancelling on the first update dialog box, you’ll move on to “Available packages”. I recommend checking the following items and then click “Install selected”: (revision numbers can of course have changed since I wrote this)

  • SDK Platform Android 2.2, API 8, revision 2
  • SDK Platform Android 2.1, API 7, revision 2
  • Samples for SDK API 8, revision 1
  • Google APIs by Google Inc., Android API 8, revision 2
  • Google APIs by Google Inc., Android API 7, revision 1
  • Usb Driver package, revision 3
  • Market Licensing package, revision 1

You’ll need to “Accept all” licenses and then the download should start. You might get a question if it is ok to restart ADB at the end of the installation procedure, which it is!

Download and unzip Eclipse

You don’t have to use Eclipse. You could stop here and use a command line utility from the Android SDK to create project skeletons and edit the files with any text file editor. But I think you’ll enjoy the full development environment of Eclipse, even though it seems to have gotten its share of complaints over the years.

Download Eclipse from here:

The first option of “Eclipse IDE for Java Developers” is what you want, and click the link to the right depending on what Windows version you’re on. I ended up downloading “”.

Eclipse doesn’t have an install at all. Just unzip the files into any folder you like and start the environment with “eclipse.exe”.

Install the Android plugin for Eclipse and point to the Android SDK

Inside Eclipse, you need to do a few things before you can create your first Android project. When you start Eclipse, you choose your “Workspace”. Just accept the default. This is the base folder where you will put all of your projects, and can of course be changed later on.

Now, do the following:

  1. Select Help menu
  2. Install new software
  3. Add
  4. Type any Name, like “Android”
  5. Paste this address in Location:
  6. OK
  7. After a few seconds, the list should contain “Developer Tools” and there you’ll find “Android DDMS” and “Android Development Tools”.
  8. Select both and then Next
  9. Continue with the download and install. You’ll be asked to restart Eclipse at the end. Do that.

Back in Eclipse with the Android plugin now installed, you also need to:

  1. Select Window menu
  2. Preferences
  3. Android
  4. Click Browse button next to “SDK Location”
  5. Point to the folder where you unzipped the Android SDK previously. For me, that would be “C:\Android\SDK” (where the “SDK Manager.exe” is located)
  6. OK
  7. Apply
  8. After a few seconds the list should fill with the Android platforms you chose to download with “SDK Manager” previously
  9. OK

That’s it!

Create your first Android project

Now you should be able to create your first Android project. Still in Eclipse:

  1. Select File menu
  2. New
  3. Project
  4. Android, Android Project
  5. Next
  6. Project name: My first project
  7. Build Target, Target Name: check any platform version you’d like to start with
  8. Application name: MyFirstProject
  9. Package name: com.myname.MyFirstProject
  10. Create Activity: (checked) MainActivity
  11. Min SDK Version: (can be left empty)
  12. Next
  13. Finish (no test project for your first attempt)

Now, right-click the project name in the left pane and choose “Run as” and then “1 Android Application”. The emulator should start and after some time (it IS really slow to start), you’ll be running your first Android application. If the emulator starts, but not your application, just keep the emulator running and switch back to Eclipse and execute the “Run as” command again. Sometimes it fails on the first attempt.

Android Installation on Windows7 and Creating a Simple Hello World Program

Mobility is driving you crazy . You wish to create a simple “HelloWorld” program that runs on Android OS. … But you are now confused as to ….How do I go about it or where do I start ?

This post is for “Beginners in Android”. So if you are completely new, this post should be of help :) ……

What Is Android ?
Android is an operating system for mobile devices. Applications developed for Android are written in Java programming language.

How do I setup the enviornment for developing applications on Android?
To setup the environment , follow these simple steps:

1) Identify the operating system on your PC. Verify whether it is listed in the “Supported Operating Systems” section. Click on this link to verify

2)  Applications for Android are written using Java programming language.Set up the environment to “DEVELOP” Java Programs.

If you have to only run Java programs, then install Java Runtime Environment(JRE). But we will be developing programs, so install Java Development Kit(JDK) which includes JRE . There is no need of separate installation of JRE if JDK is installed.
Note: Identify the operating system and choose the correct version of JDK.
Click on below link to install JDK :

3) Surely you won’t write programs in Notepad. You will use an IDE(Integrated Development Environment) to code your applications. Preferred IDE would be Eclipse, but applications can be developed using other IDEs.
To install Eclipse , select proper version of Eclipse(3.5 or newer).
Click on below link :
4)  To code applications , download the Android SDK . Android SDK provides tools and APIs to develop programs for Android OS. Download the Android SDK from this link :

5)  Your installed Eclipse IDE should be capable of developing Android programs. So install the ADT plugin for Eclipse. Click here to install the same :
6) This is last but very important step. Install the essential platform components to complete the installation. This is done using Android SDK and AVD Manager which is installed once you install the SDK.

The above steps may differ depending upon your previous installations if you were developing Java programs. You can log on to to know more .

In my case , JDK was installed on D drive and the Android SDK on E Drive. I followed the above steps with simple but important settings.
You can relate the above steps to screenshots given below.

Step 1 : Operating System : Windows 7 64 bit


Step 2 : JDK Installation Folder: D:\JavaInstallations\JDK . Set the PATH variable to point to JDK installation.


Step 3,4 : Android SDK zipped package and Eclipse zipped package unzipped at folder location : E:\Programs\Android\Software

Step 5 : Open Eclipse. Select Help-> Install New Software . You will come across the below window. Enter the remote site name  . Select the checkboxes and complete installation . Click this link for any problem..

Step 6 :

a) Android SDK and AVD Manager to install the remaining components. My folder location of this manager is E:\Programs\Android\Software\android-sdk_r08-windows\android-sdk-windows .


Run it and select all to install. After Installation, i could see all the installed packages .


Now lets just create a Simple project in Eclipse real quick:

1) Open Eclipse.Click on the eclipse symbol to load Eclipse.


2) Set the workspace. It is place to store your programs. On File Menu .. Select New -> Project. You will come across below screen.

NOTE: In my case, I had to set the Location of Android SDK in Preferences, so as to let the eclipse locate the Android Tools and APIS for development

3) Set the Project Name(on top.. hidden in image), Application Name, PackageName(can be of any order), Activity.. setting Min SDK version is not mandatory.


4) You will see a folder structure with some default code.


4) Run the Application AS Android Application.

5) Do not worry, There will be many windows popping up.. but they will start the EMULATOR or SIMULATOR which will run the program.

6) Click on Menu.. You should see HelloWorld … Not magic :) Hello World Code is already written to get u started.. :)


Getting Setup To Develop Android Apps

These are the steps that I took to get my computer (running Vista) setup for developing Android Apps.

Step One: Install JDK (Version 5 or 6). (Download From Here)

I installed JDK 6 Update 21.

Step Two: Install the Android SDK. (Download From Here)

  1. Run the SDK Setup.exe.
  2. Click on Available Packages.
  3. Select the checkbox next to https//
  4. Select a specific package(s) or Install All. You need at least one platform so that you can setup an Android Virtual Device (AVD) to run in the emulator. I installed all but I only use SDK Platform Android 2.1 since that is what is on the Ally. The USB Driver is only needed if you are developing on Windows and you have an Android device that you will use to install your app for debugging and testing.
  5. Click on the Install Selected button.

Remember where you install the SDK, you will need that information when you configure the Android Plugin.

Step Three: Install Eclipse (Version 3.5) (Download From Here)

I installed Eclipse Galileo Classic 3.5.2.

Step Four: Install Android Plugin for Eclipse

  1. Start Eclipse.
  2. Click on the Help menu.
  3. Click on Install New Software.
  4. Click the Add button in the Available Software.
  5. Enter “Android Plugin” for name.
  6. Enter https://dl-ssl.googl…ndroid/eclipse/—– If you have trouble acquiring the plugin, try to use http instead of https.
  7. Click the OK button.
  8. Select the checkbox next to Developer Tools.
  9. Click the Next button. (Twice)
  10. Accept the license agreement.
  11. Click Finish.
  12. Restart Eclipse.

Step Five: Configure the Android Plugin

  1. Click on the Window menu.
  2. Select Preferences.
  3. Click on Android in the left panel.
  4. Click on the Browse button.
  5. Locate your SDK directory – This is the path to where you installed the Android SDK.
  6. Click on the Apply button.
  7. Click on OK.

Step Six: Install the USB Drivers (Windows Only)
Note: See my post below for installing the USB Drivers using PDANet.
Note: Every computer is a little different and the steps listed here may or may not work for your computer. A more complete set of instructions is available here: