tags:

views:

32

answers:

2

Hi All,

i'm working on gpsprovider,If user click on a gps based applications for suppose map application it has check whether the gps provider enabled or not if not alert the user enable the gpsprovider .

There will be a Broadcast Receivier. Will define a message for requesting the service from any application. Will start service if not started. Will define a message for stating that the application no longer needs it. Will stop service if no app needs it anymore

+1  A: 

AFAIK it is still not possible to start the GPS service programatically. The only thing you can do is open the settings page for the user to change the setting them selves:

if(!LocationManager.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER )) 
{
    Intent myIntent = new Intent( Settings.ACTION_SECURITY_SETTINGS ); startActivity(myIntent);
}
Scoobler
A: 
  String provider = Settings.Secure.getString(getContentResolver(),     Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
    if(provider != null ){      
        if(! provider.contains("gps")){    
            // Notify users and show settings if they want to enable GPS
            new AlertDialog.Builder(MessagePage.this)
            .setMessage("GPS is switched off. enable?")
            .setPositiveButton("Enable GPS", new DialogInterface.OnClickListener(){

                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                    Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                    startActivityForResult(intent, 5);
                }
            })
            .setNegativeButton("Don't do it", new DialogInterface.OnClickListener(){

                public void onClick(DialogInterface dialog, int which) {

                }
            })
            .show();
        }
    }

      protected void onActivityResult(int requestCode, int resultCode, Intent data){
       if(requestCode == 5 && resultCode == 0){
           String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
           if(provider != null){
               switch(provider.length()){
               case 0:                     
                    //GPS still not enabled..
                   break;
               default:
                   Toast.makeText(this, "GPS is now enabled.", Toast.LENGTH_LONG).show();
                   break;
               }
           }
       }
       else{
           //the user did not enable his GPS
       }
}
Umesh