Broadcast receiver for GPS provider disabled only
am currently using bestprovider() where android itself chooses best
provider based on my criteria, every thing is fine but this location
update is done using service so how can I notify user
when GPS is disabled show location settings to user to enable GPS
when internet is disabled show Mobile network settings to user to enable
internet.
I have done this when I was receiving location updates using activity, but
now am using service and if I use same method the app is crashing.
/*----------Method to create an AlertBox ------------- */
protected void alertbox(String title, String mymessage) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Your Device's GPS is Disabled")
.setCancelable(false)
.setTitle(" Gps Status")
.setPositiveButton("Gps On",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// finish the current activity
// AlertBoxAdvance.this.finish();
Intent myIntent = new Intent(
android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(myIntent);
dialog.cancel();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// cancel the dialog box
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
calling the above as this when GPS is off alertbox("Gps Status!!", "Your
GPS is: OFF");
But this is giving me error when I call this from service? why? what I
should do to have alert from service or notify activity and then call this
method from activity?
No comments:
Post a Comment