Wednesday, June 29, 2011

Checking SD card Existance

The below method returns true if the sd card is present on the mobile else it returns false.
public static boolean isSdPresent()
{                
      return android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);        }

How to install Android Apps

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.

what is the Android

 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

Tuesday, June 28, 2011

Preventing Screen to Lock while Application is running in Android / Hiding Screen Lock while app running

To prevent lock while running the application can be done two ways.
->PowerManager
->WindowManager
Using Power Manager is not a good way. They easily drain battery. So using Window Manager we can avoid the screen locking while application is running. Add the below snippet in your activity to avoid screen lock :
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

No permissions required. Put the above code in the activity.

Thursday, June 16, 2011

Get Current Location in Android / Obtaining User Location

In Android Three Approaches are preferred to Get Current Location -> Using GPS -> Cell - Id -> Wi-Fi The above three gives a clue to get the current location. Gps gives the results accurately. But it consumes Battery. Android Network Location Provider get the current location based wifi signals and cell tower. We have to use both  or a single to Get the Current Location
LocationManager myManager;
MyLocListener loc;
loc = new MyLocListener();
myManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
myManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc );
package com.gps.activities;
import android.location.Location;
import android.location.LocationListener;
import android.os.Bundle;
public class MyLocListener implements LocationListener
{
    //Here you will get the latitude and longitude of a current location.
    @Override
    public void onLocationChanged(Location location)
    {
            if(location != null)
            {
                     Log.e("Latitude :", ""+location.getLatitude());
                     Log.e("Latitude :", ""+location.getLongitude());
            }
    }
    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub
       
    }
    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub
       
    }
    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub
       
    }
}
Note: 
 Include the below permissions in manifast.xml to listen Location Updates.

<uses-permission       android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission     android:name="android.permission.ACCESS_COARSE_LOCATION"/>
Note : If you want more details about Obtaining User Location/ Get User Location refer the below link. http://developer.android.com/guide/topics/location/obtaining-user-location.html

Tuesday, June 14, 2011

Shared Preferences Persistent Storage in Android

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 commit the values. Otherwise the values are not modified.

Monday, June 13, 2011

Publising the android application to market place

Signing is the final step of the development of an application. In order to submit any application to the android market place you have to sign the application.Signing can be done in two ways. Manually and with the help of editor(eclipse). With the help of editor it is very easy to sign an application.
Using Eclipse:

-> Right click on the project
-> In the Menu select Android Tools
-> Select Export Signed Application package. The following menu appears.
   Date Slider is the name of the project. Click on Next.
    If you have any keystore then select existing keystore. Otherwise select the other option and fill the appropriate details. Click on the next.
Minimum validity is 10000 days but 25 years Recommended. Fill the other details. Click the Next.
Browse the destination file path And click on Finish.

Note :
-> Before signing the application check the manifast file for the android:debuggable if it exist then   remove the this tag.
-> Versioning the  application properly.
-> Test the application completely.

If You want complete information then refer the following link
http://developer.android.com/guide/publishing/app-signing.html

Friday, June 10, 2011

Handling Orientation Change in Android

If you want perform some operation in the orientation the following snippet 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   

getting current screen orientation in android

The following snippet gives the current screen orientation.

public int getScreenOrientation()
{
        return getResources().getConfiguration().orientation;
}

The above method return integer. We will compare as follows.

 if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT)
 {
            //App is in Portrait mode
 }
 else
{
           //App is in LandScape mode
}