AlertDialog
UIをブロックするため、が表示されたときにユーザーがアクションを実行するのを待つ方法がないというさまざまな投稿を読みました。
ただし、Facebook
たとえば、GPSを表示するようなアプリは現在無効になっています。GPSを有効にしますか?警告ダイアログを表示し、ユーザーがyes/noを押すのを待ちます。2つの異なるアクティビティを使用できると思います。最初のアクティビティにはgpsアラートダイアログのみが含まれていますが、これは正しくないようで、Facebookのようには見えません。
誰かが私にこれを達成する方法を教えてもらえますか?
これは私のコードです:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
InitializeComponents();
EnableGPSIfPossible();
ListAsync lAsync = new ListAsync(this);
lAsync .execute();
}
private void EnableGPSIfPossible()
{
final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );
if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
buildAlertMessageNoGps();
}
}
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
したがって、私のコードではAsynTask
、ユーザーがgpsをアクティブ化するのを待たずに、すぐに起動します。(これは通常の動作です)
ありがとうございました!