Android GPS enable in code (through Programatically)

2011. 10. 11. 23:36MISCELLANEOUSNESS



private void turnGPSOn(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
	    if(!provider.contains("gps")){ //if gps is disabled
    	Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
    	intent.putExtra("enabled", true);
    	sendBroadcast(intent);
    }
}
	
private void turnGPSOff(){
    String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
	    if(provider.contains("gps")){ //if gps is enabled
    	Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
    	intent.putExtra("enabled", false);
    	sendBroadcast(intent);
    }
}





원문 보기: http://androidfreakers.blogspot.com/2011/09/enable-or-disable-gps-in-android.html