我希望我的應用程序只有在打開GPS時才能運行,以下是我迄今爲止所做的活動。如何禁用Android中AlertDialog的所有其他操作?
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
setUpMapIfNeeded();
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
checkForGPS();
}
private void checkForGPS(){
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle(getResources().getString(R.string.gps_error_title));
alertDialog.setMessage(getResources().getString(R.string.gps_error_message));
alertDialog.setButton(getResources().getString(R.string.alert_button_turn_on), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
}
});
if(!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
alertDialog.show();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
checkForGPS();
}
現在我有這個對話框的問題,因爲它工作正常,但我能夠按下我的後退按鈕,只是忽略它。我怎麼解決這個問題?
檢查此問題http://stackoverflow.com/questions/22627663/android-alertdialog-user-click-somewhere-else/22627698#22627698 –
你是什麼意思,因爲它工作正常,但我能夠按我的後退按鈕,只是忽略它。「? – Setu
@Setu我的意思是它做它必須做的事情,它的按鈕) – Carmine