I have an alert dialog with a custom layout that when the gps or network are not enabled it will pop up so the user can enable them.
Here is the code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get Location Manager and check for GPS & Network location services
final LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
View mView = getLayoutInflater().inflate(R.layout.activity_gps_alert_dialog, null);
Button positiveBtn = (Button) mView.findViewById(R.id.positiveBtn);
final Button negativeBtn = (Button) mView.findViewById(R.id.negativeBtn);
builder.setView(mView);
final AlertDialog dialog = builder.create();
positiveBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Show location settings when the user acknowledges the alert dialog
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
negativeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
System.exit(0);
}
});
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
The problem is that this popup dialog is on the screen even if the GPS and network are enabled and even if the user enables them through it the alertdialog still stays on the screen.