2014-04-16 5 views
0

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. 

답변

1

당신은 다음과 같이 다음 AlertDialog 사용 show() 방법을 보여 AlertDialog.Builder 객체에서 AlertDialog를 만들 필요가

alertDialogue.show(); 
0

표시합니다. ..

AlertDialog dialog = alertDialogue.create(); 
dialog.show(); 

아래와 같이 showGPSDialogueBox()을 업데이트하십시오 ...

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(); 

     } 
    }); 

    AlertDialog dialog = alertDialogue.create(); 
    dialog.show(); 
} 
관련 문제