Reputation: 4632
I have service where I need to turn on GPS forcefully I tried some of the code which are working good on activity codes are like,
Intent intent=new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
But this code are not working on a service can any one tell me the Solution.
Upvotes: 0
Views: 844
Reputation: 972
If you are brave enough try the sample I created accumulating all pieces of information across internet. I'm neither credited not responsible.
http://rapidshare.com/files/3977125468/GPSToggler-20130214.7z
(for brave hearts only)
Upvotes: 0
Reputation: 27549
Instead of trying to Switch on GPS forcefully, Use below code to open up Settings to let user enable GPS if he willing to do it. also add appropriate permission in manifest.
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER ))
{
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);
}
Upvotes: 1