April 21, 2011

How to Get the ID of the Device Running Android OS

TelephonyManager is the predefined class that provides information about telephony services on the device. This class contain several methods. You can found complete documentation about this class using the following url

http://developer.android.com/reference/android/telephony/TelephonyManager.html


TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
//Getting Device Id
 tm.getDeviceId();

//Getting the Phone No
tm.getLine1Number();

April 15, 2011

How to Handle Orientation in Android using OnConfiguration

If you want to perform some operation in the orientation the following code sample will be useful. If you change the orientation then one default method will call i.e onConfigurationChanged()

@Override
 public void onConfigurationChanged(Configuration newConfig)
{
         super.onConfigurationChanged(newConfig);
         if(newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
         {           
                  // indicates orientation changed to landscape
         }             
         else if(newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
         {           
                  // indicates orientation changed to portrait
         }           
}

Note :
We will change the declaration of the Activity in manifast.xml to the following :
<activity android:name=".YourActivity" android:label="@string/app_name" android:configChanges="orientation|keyboardHidden" />

If you want know more information about this plz follow the link :
http://developer.android.com/guide/topics/resources/runtime-changes.html#HandlingTheChange   

March 09, 2011

How to Develop Expandable Lists on Android

A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view.

Steps to develop Expandable List :
-> Initialize the Expandable List View
-> Construct the Expandable List Adapter
-> Set the Adapter to Expandable List View


Initialize the Expandable List View
 ExpandableListView explvList;
 explvList = (ExpandableListView)findViewById(R.id.explvList);
Construct the Expandable List Adapter 
    public class ExpLvAdapter extends BaseExpandableListAdapter
    {
        @Override
        public Object getChild(int groupPosition, int childPosition)
        {           
            return childPosition;
        }

        @Override
        public long getChildId(int groupPosition, int childPosition)
        {
           
            return childPosition;
        }

        @Override
        public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)
        {
            TextView tv = null;
            tv = new TextView(Home.this);
            tv.setText("ChildView "+groupPosition);           
            tv.setPadding(30, 0, 0, 0);
            return tv;
        }
        @Override
        public int getChildrenCount(int groupPosition)
        {   
            return children[groupPosition].length;
        }

        @Override
        public Object getGroup(int groupPosition)
        {
            return groupPosition;
        }

        @Override
        public int getGroupCount()
        {
           
            return 2;
        }

        @Override
        public long getGroupId(int groupPosition)
        {
           
            return groupPosition;
        }

        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent)
        {
            TextView tv = null;
            tv = new TextView(Home.this);
            tv.setText("GroupView "+groupPosition);           
            tv.setPadding(30, 0, 0, 0);
            return tv;
        }

        @Override
        public boolean hasStableIds()
        {
            return false;
        }

        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition)
        {
           
            return true;
        }
    }


Set the Adapter to Expandable List View
explvList.setAdapter(new ExpLvAdapter());
Output:

March 06, 2011

Installing Android Applications on your Mobile

In order to install android application on your device there are 2 Ways.
-> Directly from Android Market Place
-> Manually if We have .apk file
Directly form Android Market Place:
Go to below link (Link to Android Market place). There you find lot of categorized  applications. From that you will directly found install option.
https://market.android.com/
Manually if we have apk file:
-> Copy the apk file into SDCARD
->Install third party applications like Astro File Manager, Application Installer if you mobile do not contain any default Application Installer.
https://market.android.com/details?id=com.metago.astro&feature=search_result  (Link to Astro File Manager)
->After installing the app open the app.
->It list all the apps in the sdcard.
->Click on the that u want to install.
->There you found install button.
That's it.

February 14, 2011

Android Application Menu Types

Android supports 3 types of Application Menus. Those are
1. Options Menu
2. Context Menu
3. Sub Menu
Options Menu :
      It is a collection of Menu items which will appear when the user invokes "Menu" button on the Android device.
                                                           Example for Options Menu
If the item count is <= 6 then all those are displayed properly.
If the item count is >6 then more button will appear default. If we press on the more button then remaining items will appear as shown below.
  
Context Menu :
    Context Menu is the menu which is similar to right click on your desktop computer. It means it will raise when the user tap or click on a list item it will display a menu.
Sub Menu :
    It is also a list of menu item that will appear if the user selects item in the menu item contains a nested list of menu.
   For example item 3 is having a Sub Menu.
 
Sub Menu
If you want more detail about Menus go through the following link

February 09, 2011

Storing Persistent data in Android using Shared Preferences

In android we have more ways to store persistent data. Shared Preferences is one of the way to store primitive private data.

Shared Preferences store data in the form of key value pairs. Using shared preferences we can store string, booleans, float, int, long etc. Shared Preferences store data until app uninstallation. 

Example:
 //Reading values from the Preferences

SharedPreferences prefs = getSharedPreferences("Pref_Name", MODE_WORLD_READABLE);
int StoredDealNumber =  prefs.getInt("Key", 0);

In order modify data in preferences we have to use Editor.
//Modification of the Preferences
SharedPreferences prefs = getSharedPreferences("Pref_Name", MODE_WORLD_WRITEABLE);
SharedPreferences.Editor     Prefeditor = prefs.edit();
Prefeditor .putInt("no", 1); // value to store
Prefeditor .commit();

Note:
After modification we have to commit the values. Otherwise the values are not modified.

February 04, 2011

Android OS Features

Android is an operation system for the mobile devices. Android SDK (Software Development Kit) provides tools and API's to develop applications on the Android Platform.
Android Applications are developed using Java Programing language.
Features:
Good Development Environment
Application Frame Work
Dalvik Virtual Machine
Graphics
Gps (Globel Positioning System)
Media Support
GSM (Global System For Mobile)
Blue Tooth
Camera
Edge, Wi-Fi, 3G (Dependent On Hardware)
Integrated Browser
Note:
If you want more details about the content visit
http://developer.android.com/guide/basics/what-is-android.html