This android tutorial is to help learn location based service in android platform. Knowing the current location in an android mobile will pave the way for developing many innovative Android apps to solve peoples daily problem. For developing location aware application in android, it needs location providers. There are two types of location providers,
  1. GPS Location Provider
  2. Network Location Provider

    
  



Network Location Provider vs GPS Location Provider

  • Network Location provider is comparatively faster than the GPS provider in providing the location co-ordinates.
  • GPS provider may be very very slow in in-door locations and will drain the mobile battery.
  • Network location provider depends on the cell tower and will return our nearest tower location.
  • GPS location provider, will give our location accurately.
 
   

Create LocationManager instance as reference to the location service

For any background Android Service, we need to get reference for using it. Similarly, location service reference will be created using getSystemService() method. This reference will be added with the newly created LocationManager instance as follows.
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);



Request current location from LocationManager

After creating the location service reference, location updates are requested using requestLocationUpdates() method of LocationManager. For this function, we need to send the type of location provider, number of seconds, distance and the LocationListener object over which the location to be updated.
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);



Receive location update from LocationListener on change of location

LocationListener will be notified based on the distance interval specified or the number seconds.






package com.shir60bhushan.gpsLocation;
 
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.TextView;
 
import android.util.Log;
 
public class MainActivity extends Activity implements LocationListener{
protected LocationManager locationManager;
protected LocationListener locationListener;
protected Context context;
TextView txtLat;
String lat;
String provider;
protected String latitude,longitude; 
protected boolean gps_enabled,network_enabled;
 
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtLat = (TextView) findViewById(R.id.textview1);
 
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
@Override
public void onLocationChanged(Location location) {
txtLat = (TextView) findViewById(R.id.textview1);
txtLat.setText("Latitude:" + location.getLatitude() + ", Longitude:" + location.getLongitude());
}
 
@Override
public void onProviderDisabled(String provider) {
Log.d("Latitude","disable");
}
 
@Override
public void onProviderEnabled(String provider) {
Log.d("Latitude","enable");
}
 
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d("Latitude","status");
}
}
Xml layout will be As follows

 
    
 




It is very common that you have seen some simple animations in most of the applications in Android. Animations can give better user experience for your applications. In this example, I’ll try to introduce you doing simple animations with Android. It is simple enough that on clicking a button, an images starts rotating from 0 degree to 360 degree in N seconds. Lets begin with the animation XML. Once you have created a new Android project, create a folder named anim in res and a file named rotator.xml inside res/anim.

android:duration="”4000”" 
android:fromdegrees="”0”" 
android:pivotx="”50%”" 
android:pivoty="”50%”"
android:todegrees="”360”" 
android:toyscale="”0.0”" 

Hope the code is pretty self explanatory. Here one complete rotation will be completed in 4000ms (4 seconds). Now add a PNG image that you want to rotate into your drawable folder. Then open res/main.xml, after removing the default textView in the layout, add an ImageView and Button into the layout. Set the src property of the ImageView as your filename of the added image, for example android:src=”@drawable/myimg” Ok, lets edit the main class. In the onClick() for the button, add the necessary code for running the animation. Check the following code.
public class AnimationActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener()    {
            @Override
            public void onClick(View arg0) {
                final ImageView myImage = (ImageView)findViewById(R.id.imageView1);
                final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);
                myImage.startAnimation(myRotation);
            }
        });
    }
}



Blazin Battery Saver



Blazin battery saver Application launched recently which is a battery optimisation tool having sleek look and feel and making plenty of downloads on the google play


https://play.google.com/store/apps/details?id=com.shir60bhushan.blazinbattery&hl=en

have a look on it ,.