-3

Possible Duplicate:
ICS Android enable gps programmatically? [closed using an alternative approach]

I was using the code below to enable and disable GPS programmatically and worked perfectly in 2.2 and 2.3.

Intent i = new Intent();
i.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
i.addCategory(Intent.CATEGORY_ALTERNATIVE);
i.setData(Uri.parse("3"));     
context.sendBroadcast(i);

However, when trying to use the ICS (4.0) realized it did not work. Then I discovered that it was a bug as link below. http://code.google.com/p/android/issues/detail?id=7890

I believe we have fixed in ICS.

Could anyone tell me if there is an alternative to solve this in ICS?

I think an OS ridiculous "open source" have so many restrictions. I'm already starting to regret having opted to develop our applications on Android.

Community
  • 1
  • 1

2 Answers2

1

I believe it is a security feature that you cannot programmatically alter the GPS state.

Why does open source mean it shouldn't have restrictions? I'm confused. Open source just means you have access to the source code.

On a personal note, developing for Android was much less painful than developing for iOS using Cocoa Touch.

EDIT:

Try using this to let the user know they need to enable GPS.

(source: http://manishkpr.webheavens.com/android-syste-gps-setting-intent/)

private void checkGPS(){
     locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
     locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, this);
     boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER);
     if(isGPS){
        showToast("Gps On");
     }else{

        startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
     }
}
coder543
  • 803
  • 6
  • 16
0

Those restrictions are because of security issues. You should not try to achieve this case because it works now, but in next few days can be fixed - for example custom roms.

The best solution to manage GPS is to open Android's GPS preferences and let user to enable/disable GPS manually.

hsz
  • 148,279
  • 62
  • 259
  • 315