PnzrDrgoon
Lurker
SOLVED BELOW
Below is the snippet of code that isn't working how I think it should. What I want it to do is detect if GPS is currently on. If not, then throw up an AlertDialog letting the user know I want it enabled, and then open the screen for them so they can turn it on. It's detecting the GPS status correctly, but the dialog box never appears causing an infinite loop. What else do I need to do aside from show()ing the AlertDialong?
Below is the snippet of code that isn't working how I think it should. What I want it to do is detect if GPS is currently on. If not, then throw up an AlertDialog letting the user know I want it enabled, and then open the screen for them so they can turn it on. It's detecting the GPS status correctly, but the dialog box never appears causing an infinite loop. What else do I need to do aside from show()ing the AlertDialong?
PHP:
public void toggleGPS()
{
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
while(!lm.isProviderEnabled(LocationManager.GPS_PROVIDER )) {
AlertDialog.Builder alt_bld = new AlertDialog.Builder(AssetTracking.this);
alt_bld.setMessage("Please enable GPS.")
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent myIntent = new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS );
startActivity(myIntent);
}
});
AlertDialog alert = alt_bld.create();
alert.show();
}
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, (LocationListener) this);
}