Tuesday, 19 January 2021

Implement In-app Update In Android

 implementation 'com.google.android.play:core:1.9.0'


MainActivity.java

package raj.sujeet.com.historycalendar;

import androidx.annotation.Nullable;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;

import android.content.Intent;

import android.content.IntentSender;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.widget.Toast;

import com.google.android.material.snackbar.Snackbar;

import com.google.android.play.core.appupdate.AppUpdateInfo;

import com.google.android.play.core.appupdate.AppUpdateManager;

import com.google.android.play.core.appupdate.AppUpdateManagerFactory;

import com.google.android.play.core.install.InstallState;

import com.google.android.play.core.install.InstallStateUpdatedListener;

import com.google.android.play.core.install.model.ActivityResult;

import com.google.android.play.core.install.model.AppUpdateType;

import com.google.android.play.core.install.model.InstallStatus;

import com.google.android.play.core.install.model.UpdateAvailability;

import com.google.android.play.core.tasks.OnSuccessListener;

import com.google.android.play.core.tasks.Task;


public class MainActivity extends AppCompatActivity {

    private AppUpdateManager appUpdateManager;

    private static final int MY_REQUEST_CODE = 17326;


    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        checkUpdate();

    }


    private void checkUpdate() {

InstallStateUpdatedListener listener = new InstallStateUpdatedListener() {

        @Override

        public void onStateUpdate(InstallState installState) {

            if (installState.installStatus() == InstallStatus.DOWNLOADED) {

                Log.d("InstallDownloded", "InstallStatus sucsses");

                notifyUser();

            }

        }

    };

        appUpdateManager = AppUpdateManagerFactory.create(this);

        appUpdateManager.registerListener(listener);


        Task<AppUpdateInfo> appUpdateInfoTask = appUpdateManager.getAppUpdateInfo();

        appUpdateInfoTask.addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {

            @Override

            public void onSuccess(AppUpdateInfo appUpdateInfo) {

                String data = "packageName :" + appUpdateInfo.packageName() + ", " +

                        "availableVersionCode :" + appUpdateInfo.availableVersionCode() + ", " +

                        "updateAvailability :" + appUpdateInfo.updateAvailability() + ", " +

                        "installStatus :" + appUpdateInfo.installStatus()+ ", ";


                Log.e("appUpdateInfo :", ""+data);

                Toast.makeText(MainActivity.this, ""+data, Toast.LENGTH_LONG).show();


                if (appUpdateInfo.updateAvailability() == UpdateAvailability.UPDATE_AVAILABLE

                        && appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE)) {

                    requestUpdate(appUpdateInfo);

                    Log.d("UpdateAvailable", "update is there ");

                } else if (appUpdateInfo.updateAvailability() == UpdateAvailability.DEVELOPER_TRIGGERED_UPDATE_IN_PROGRESS) {

                    Log.d("Update", "3");

                    notifyUser();

                } else {

                    Toast.makeText(MainActivity.this, "No Update Available", Toast.LENGTH_SHORT).show();

                    Log.e("NoUpdateAvailable", "update is not there ");

                }

            }

        });

    }


    private void requestUpdate(AppUpdateInfo appUpdateInfo) {

        try {

            appUpdateManager.startUpdateFlowForResult(appUpdateInfo, AppUpdateType.IMMEDIATE, MainActivity.this, MY_REQUEST_CODE);

            resume();

        } catch (IntentSender.SendIntentException e) {

            e.printStackTrace();

        }

    }


    @Override

    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {

        super.onActivityResult(requestCode, resultCode, data);


        if (requestCode == MY_REQUEST_CODE) {

            switch (resultCode) {

                case Activity.RESULT_OK:

                    if (resultCode != RESULT_OK) {

                        Toast.makeText(this, "RESULT_OK" + resultCode, Toast.LENGTH_LONG).show();

                        Log.d("RESULT_OK  :", "" + resultCode);

                    }

                    break;

                case Activity.RESULT_CANCELED:


                    if (resultCode != RESULT_CANCELED) {

                        Toast.makeText(this, "RESULT_CANCELED" + resultCode, Toast.LENGTH_LONG).show();

                        Log.d("RESULT_CANCELED  :", "" + resultCode);

                    }

                    break;

                case ActivityResult.RESULT_IN_APP_UPDATE_FAILED:


                    /*if (resultCode != RESULT_IN_APP_UPDATE_FAILED){


                        Toast.makeText(this,"RESULT_IN_APP_UPDATE_FAILED" +resultCode, Toast.LENGTH_LONG).show();

                        Log.d("RESULT_IN_APP_FAILED:",""+resultCode);

                    }*/

            }

        }

    }


    @Override

    protected void onDestroy() {

        super.onDestroy();

        try {

            appUpdateManager.unregisterListener((InstallStateUpdatedListener) this);

        }catch (RuntimeException e){


        }


    }


    private void notifyUser() {


        Snackbar snackbar =

                Snackbar.make(findViewById(R.id.root),

                        "An update has just been downloaded.",

                        Snackbar.LENGTH_INDEFINITE);

        snackbar.setAction("RESTART", new View.OnClickListener() {

            @Override

            public void onClick(View view) {

                appUpdateManager.completeUpdate();

            }

        });

        snackbar.setActionTextColor(

                getResources().getColor(R.color.colorAccent));

        snackbar.show();

    }


    private void resume() {

        appUpdateManager.getAppUpdateInfo().addOnSuccessListener(new OnSuccessListener<AppUpdateInfo>() {

            @Override

            public void onSuccess(AppUpdateInfo appUpdateInfo) {

                if (appUpdateInfo.installStatus() == InstallStatus.DOWNLOADED) {

                    notifyUser();


                }


            }

        });

    }

}


Saturday, 6 June 2020

RecyclerView scroll checkbox auto select issue solution

if(classModelList.get(myViewHolder.getAdapterPosition()).isCheckBoxStatus())
    myViewHolder.classCB.setChecked(true);
else    myViewHolder.classCB.setChecked(false);

myViewHolder.classCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    @Override    public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
        if (b) {
            classModelList.get(myViewHolder.getAdapterPosition()).setCheckBoxStatus(true);
            //listAllListeners.onItemCheck(holder.checkBoxTime.getText().toString(), holder.getAdapterPosition());        }
        else {
            classModelList.get(myViewHolder.getAdapterPosition()).setCheckBoxStatus(false);
            //listAllListeners.onItemUncheck(holder.checkBoxTime.getText().toString(), holder.getAdapterPosition());        }
    }
});

Thursday, 10 October 2019

Shadow effect Elevation

<LinearLayout    android:layout_width="match_parent"    android:layout_height="200dp"    android:layout_gravity="center"    android:gravity="center"    android:layout_margin="20dp"    android:elevation="10dp"    android:clickable="true"    android:background="@drawable/ripple_effect2"    >
</LinearLayout>

<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text="Elevation Example"    android:layout_gravity="center"    android:gravity="center"    android:elevation="5dp"    android:padding="20dp"    android:layout_marginTop="20dp"    android:layout_marginBottom="20dp"    android:background="@drawable/ripple_effect"    android:clickable="true"    ></TextView>






<?xml version="1.0" encoding="utf-8"?><ripple xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:color="#dddddd"    tools:targetApi="lollipop">

    <item android:id="@android:id/background">
        <shape xmlns:android="http://schemas.android.com/apk/res/android"            android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <stroke                android:width="3dp"                android:color="#FFFFFF" />
            <corners android:bottomLeftRadius="15dp"                android:topLeftRadius="15dp"                android:bottomRightRadius="15dp"                android:topRightRadius="15dp" />
            <padding                android:bottom="0dp"                android:left="0dp"                android:right="0dp"                android:top="0dp" />
        </shape>
    </item>
</ripple>

Wednesday, 27 March 2019

Get Full Address From Latitude and Longitude Android Google Map

Get Full Address From Latitude and Longitude Android Google Map

String zipCode = getZipCode(MapsActivity.this,arg0.latitude,arg0.longitude);
Toast.makeText(MapsActivity.this,""+zipCode,Toast.LENGTH_LONG).show();





public String getZipCode(Context c, double lat, double lng){
    String fullAdd = null;
    String locality = null;
    String zip = null;
    String country = null;
    try {
        Geocoder geocoder = new Geocoder(c,Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(lat,lng,1);
        if (addresses.size()>0){
            Address address = addresses.get(0);
            fullAdd = address.getAddressLine(0);  // full Address  
            locality = address.getLocality();
            zip = address.getPostalCode();
            country = address.getCountryName();
        }

    }catch (IOException ex){
        ex.printStackTrace();
    }
    return zip;
}

Monday, 4 February 2019

SMS Permission Run time Android Studio

AndroidManifest.xml

<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>


MainActivity.java


package com.sjt.smspermissionruntime;
import android.Manifest;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class MainActivity extends AppCompatActivity {
public static final int REQUEST_ID_MULTIPLE_PERMISSIONS = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (checkAndRequestPermissions()) {
// carry on the normal flow, as the case of permissions granted.
// Toast.makeText(SignUp.this,"Granted",Toast.LENGTH_LONG).show();
}
}
private boolean checkAndRequestPermissions() {
int permissionSendMessage = ContextCompat.checkSelfPermission(this,
Manifest.permission.READ_SMS);
int locationPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.RECEIVE_SMS);
List<String> listPermissionsNeeded = new ArrayList<>();
if (locationPermission != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.READ_SMS);
}
if (permissionSendMessage != PackageManager.PERMISSION_GRANTED) {
listPermissionsNeeded.add(Manifest.permission.RECEIVE_SMS);
}
if (!listPermissionsNeeded.isEmpty()) {
ActivityCompat.requestPermissions(this,
listPermissionsNeeded.toArray(new String[listPermissionsNeeded.size()]),
REQUEST_ID_MULTIPLE_PERMISSIONS);
return false;
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode,
String permissions[], int[] grantResults) {
Log.d("Permission", "Permission callback called-------");
switch (requestCode) {
case REQUEST_ID_MULTIPLE_PERMISSIONS: {
Map<String, Integer> perms = new HashMap<>();
// Initialize the map with both permissions
perms.put(Manifest.permission.READ_SMS, PackageManager.PERMISSION_GRANTED);
perms.put(Manifest.permission.RECEIVE_SMS, PackageManager.PERMISSION_GRANTED);
// Fill with actual results from user
if (grantResults.length > 0) {
for (int i = 0; i < permissions.length; i++)
perms.put(permissions[i], grantResults[i]);
// Check for both permissions
if (perms.get(Manifest.permission.READ_SMS) == PackageManager.PERMISSION_GRANTED
&& perms.get(Manifest.permission.RECEIVE_SMS) == PackageManager.PERMISSION_GRANTED) {
Log.d("sms", "READ_SMS & RECEIVE_SMS services permission granted");
// process the normal flow
//else any one or both the permissions are not granted
} else {
Log.d("Some", "Some permissions are not granted ask again ");
//permission is denied (this is the first time, when "never ask again" is not checked) so ask again explaining the usage of permission
// // shouldShowRequestPermissionRationale will return true
//show the dialog or snackbar saying its necessary and try again otherwise proceed with setup.
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.READ_SMS) ||
ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.RECEIVE_SMS)) {
showDialogOK("READ_SMS and RECEIVE_SMS Services Permission required for this app",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
checkAndRequestPermissions();
break;
case DialogInterface.BUTTON_NEGATIVE:
// proceed with logic by disabling the related features or quit the app.
break;
}
}
});
}
//permission is denied (and never ask again is checked)
//shouldShowRequestPermissionRationale will return false
else {
// Toast.makeText(this, "Go to settings and enable permissions", Toast.LENGTH_LONG).show();
// //proceed with logic by disabling the related features or quit the app.
}
}
}
}
}
}
private void showDialogOK(String message, DialogInterface.OnClickListener okListener) {
new AlertDialog.Builder(this)
.setMessage(message)
.setPositiveButton("OK", okListener)
.setNegativeButton("Cancel", okListener)
.create()
.show();
}
}

Sunday, 9 July 2017

How to convert GPS Coordinates ( Latitude and Longitude ) to Address in Android.

Manifest
<uses-permission android:name="android.permission.INTERNET" />  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />


activity.gps.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto"   
 xmlns:tools="http://schemas.android.com/tools"    
  android:layout_width="match_parent"   
  android:layout_height="match_parent"  
  android:orientation="vertical"   
  tools:context="raj.sujeet.com.example.GPSActivity"    
android:weightSum="1">
<Button
     android:id="@+id/getLL"      
  android:layout_width="match_parent"       
 android:layout_height="wrap_content"      
  android:text="get Lati/long"       
 tools:layout_editor_absoluteX="39dp"      
  tools:layout_editor_absoluteY="28dp"        
android:layout_marginTop="10dp"        
tools:ignore="MissingConstraints"       
android:layout_weight="0.01" />
<EditText
android:id="@+id/latitude"      
  android:layout_marginTop="10dp"      
  android:layout_width="match_parent" 
       android:layout_height="wrap_content" />

    <EditText     
   android:id="@+id/longitude"    
    android:layout_marginTop="10dp"    
    android:layout_width="match_parent"   
     android:layout_height="wrap_content" />

    <Button        
android:id="@+id/getLocation" 
       android:layout_marginTop="20dp"
        android:layout_width="match_parent"  
      android:layout_height="wrap_content"  
      android:text="get location"        />

    <TextView  
      android:layout_margin="10dp" 
       android:id="@+id/result"  
      android:layout_width="wrap_content" 
       android:layout_height="wrap_content"        />

</LinearLayout>





GPSActivity.java

public class GPSActivity extends AppCompatActivity {

    Button getLL,getlocation;
    EditText latitudeLL,longitudeLL;

    String lati,longi;

    TextView result;
    Geocoder geocoder;
    List<Address> addressList;

    // GPSTracker class    GPSTracker gps;

    Context mContext;

    double latitude,longitude;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gps);

        result = (TextView)findViewById(R.id.result);
        geocoder = new Geocoder(this, Locale.getDefault());


        latitudeLL = (EditText)findViewById(R.id.latitude);
        longitudeLL = (EditText)findViewById(R.id.longitude);

        getlocation = (Button)findViewById(R.id.getLocation);

        mContext = this;

        getLL = (Button)findViewById(R.id.getLL);
        getLL.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {


                if (ContextCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_FINE_LOCATION)
 != PackageManager.PERMISSION_GRANTED                      
  && ActivityCompat.checkSelfPermission(mContext,
                        Manifest.permission.ACCESS_COARSE_LOCATION) 
!= PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(GPSActivity.this,
                            new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);

                } else {
                    Toast.makeText(mContext, "You need have granted permission",
 Toast.LENGTH_SHORT).show();
                    gps = new GPSTracker(mContext, GPSActivity.this);

                    // Check if GPS enabled                 
   if (gps.canGetLocation()) {

                         latitude = gps.getLatitude();
                        longitude = gps.getLongitude();

                        // \n is for new line         
               Toast.makeText(getApplicationContext(),
                                "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
                         lati = Double.toString(latitude);
                         longi = Double.toString(longitude);
                        latitudeLL.setText(lati);
                        longitudeLL.setText(longi);
                    } else {
                        // Can't get location.                  
      // GPS or network is not enabled.                      
  // Ask user to enable GPS/network in settings.          
              gps.showSettingsAlert();
                    }
                }

            }
        });

        getlocation.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                try {
                    addressList = geocoder.getFromLocation(latitude,longitude,1);

                    String addressStr = addressList.get(0).getAddressLine(0);
                    String areaStr = addressList.get(0).getLocality();
                    String cityStr = addressList.get(0).getAdminArea();
                    String countryStr = addressList.get(0).getCountryName();
                    String postalcodeStr = addressList.get(0).getPostalCode();

                    String fullAddress = addressStr+", "+areaStr+", "+cityStr+", "+countryStr+", "+postalcodeStr;

                    result.setText(fullAddress);

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

    }

    @Override    public void onRequestPermissionsResult(int requestCode, String[] permissions,
 int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

        switch (requestCode) {
            case 1: {
                // If request is cancelled, the result arrays are empty.       
         if (grantResults.length > 0                   
     && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                    // permission was granted, yay! Do the
                    // contacts-related task you need to do.
                    gps = new GPSTracker(mContext, GPSActivity.this);

                    // Check if GPS enabled                   
 if (gps.canGetLocation()) {

                        double latitude = gps.getLatitude();
                        double longitude = gps.getLongitude();

                        // \n is for new line                    
    Toast.makeText(getApplicationContext(),
                                "Your Location is - \nLat: " + latitude + "\nLong: " + longitude, Toast.LENGTH_LONG).show();
                    } else {
                        // Can't get location.                       
 // GPS or network is not enabled.                       
 // Ask user to enable GPS/network in settings.                       
 gps.showSettingsAlert();
                    }

                } else {

                    // permission denied, boo! Disable the                   
 // functionality that depends on this permission.
                    Toast.makeText(mContext, "You need to grant permission",
 Toast.LENGTH_SHORT).show();
                }
                return;
            }
        }
    }
}




GPSTracker.java

package raj.sujeet.com.example;

import android.Manifest;
import android.app.Activity;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.util.Log;

/** * Created by Sujeet Raj on 09-07-2017. */
public class GPSTracker extends Service {

    private Context mContext;

    // Flag for GPS status    
boolean isGPSEnabled = false;

    // Flag for network status   
 boolean isNetworkEnabled = false;

    // Flag for GPS status  
  boolean canGetLocation = false;

    Location location; 
// Location  
  double latitude;
 // Latitude   
 double longitude; 
// Longitude
    // The minimum distance to change Updates in meters   
 private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1000; 
// 10 meters
    // The minimum time between updates in milliseconds  
  private static final long MIN_TIME_BW_UPDATES = 1000 * 60 * 1; 
// 1 minute
    // Declaring a Location Manager    protected LocationManager locationManager;

    Activity activity;

    public GPSTracker() {
    }

    public GPSTracker(Context context, Activity activity) {
        this.mContext = context;
        this.activity = activity;
        getLocation();
    }

    public Location getLocation() {
        try {


            locationManager = (LocationManager) mContext.getSystemService(LOCATION_SERVICE);

            // Getting GPS status          
  isGPSEnabled = locationManager                   
 .isProviderEnabled(LocationManager.GPS_PROVIDER);

            // Getting network status          
  isNetworkEnabled = locationManager                    
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

            if (!isGPSEnabled && !isNetworkEnabled) {
                // No network provider is enabled          
  } else {
                this.canGetLocation = true;
                if (isNetworkEnabled) {
                    int requestPermissionsCode = 50;

                    locationManager.requestLocationUpdates(
                            LocationManager.NETWORK_PROVIDER,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES, mLocationListener);
                    Log.d("Network", "Network");
                    if (locationManager != null) {
                        location = locationManager                             
   .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                        if (location != null) {
                            latitude = location.getLatitude();
                            longitude = location.getLongitude();
                        }
                    }
                }
            }
            // If GPS enabled, get latitude/longitude using GPS Services      
      if (isGPSEnabled) {
                if (location == null) {
                    if (ContextCompat.checkSelfPermission(activity, 
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && 
ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                        ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 50);

                    } else {
                        locationManager.requestLocationUpdates(
                                LocationManager.GPS_PROVIDER,
                                MIN_TIME_BW_UPDATES,
                                MIN_DISTANCE_CHANGE_FOR_UPDATES, mLocationListener);
                        Log.d("GPS Enabled", "GPS Enabled");
                        if (locationManager != null) {

                            location = locationManager                                 
   .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                            if (location != null) {
                                latitude = location.getLatitude();
                                longitude = location.getLongitude();
                            }
                        }
                    }
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return location;
    }


    /**     * Stop using GPS listener    
 * Calling this function will stop using GPS in your app.    
 */   
 public void stopUsingGPS() {

    }


    private final LocationListener mLocationListener = new LocationListener() {
        @Override        public void onLocationChanged(final Location location) {

            if (location != null) {
                latitude = location.getLatitude();
                longitude = location.getLongitude();
            }
        }

        @Override        public void onStatusChanged(String provider, int status, Bundle extras) {

        }

        @Override        public void onProviderEnabled(String provider) {

        }

        @Override        public void onProviderDisabled(String provider) {

        }
    };

    /**     
* Function to get latitude   
  */   
 public double getLatitude() {
        if (location != null) {
            latitude = location.getLatitude();
        }

        // return latitude      
  return latitude;
    }


    /**     * Function to get longitude    
 */   
 public double getLongitude() {
        if (location != null) {
            longitude = location.getLongitude();
        }

        // return longitude       
 return longitude;
    }

    /**     * Function to check GPS/Wi-Fi enabled     *   
  * @return boolean     */   
 public boolean canGetLocation() {
        return this.canGetLocation;
    }


    /**     * Function to show settings alert dialog.    
 * On pressing the Settings button it will launch Settings Options.     */ 
 
  public void showSettingsAlert() {
        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);

        // Setting Dialog Title       
 alertDialog.setTitle("GPS is settings");

        // Setting Dialog Message        
alertDialog.setMessage("GPS is not enabled. Do you want to go to settings menu?");

        // On pressing the Settings button.      
  alertDialog.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                mContext.startActivity(intent);
            }
        });

        // On pressing the cancel button     
   alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        // Showing Alert Message      
  alertDialog.show();
    }


    @Override    public IBinder onBind(Intent arg0) {
        return null;
    }
}