我正在創建一個對話框,該對話框在GPS服務被禁用的情況下應該對用戶顯示。但是發生的是,雖然我手動禁用了服務以強制對話出現,但應用程序啓動並且沒有任何事情發生。對話框不顯示
下面的代碼顯示了我如何嘗試創建對話框以及何時。請讓我知道是否有任何錯誤。
JavaCode:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gpstest00);
locMgr = (LocationManager) getSystemService(LOCATION_SERVICE);
gpsEnable = locMgr.isProviderEnabled(LocationManager.GPS_PROVIDER);
if (!gpsEnable) {
showGPSDialogueBox();
}
locMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this.locationListener);
}
/*if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment()).commit();
}*/
private void showGPSDialogueBox() {
AlertDialog.Builder alertDialogue = new AlertDialog.Builder(this);
alertDialogue.setTitle("GPS Settings");
alertDialogue.setMessage("GPS is deactivated. Do you want to switch " + to settings menu to activate it?");
alertDialogue.setPositiveButton("Settings",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
}
});
alertDialogue.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
}// Enf of showDialogueBox function.