此代码能够转到 GPS 设置并将其打开,但按下后它并不打算返回应用程序。相反,它将我带到我的发射器的家。
public void createDialog(){
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle(R.string.gps_message);
alert.setPositiveButton(R.string.gps_settings, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
startActivityForResult(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0);
return;
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alert.create();
alert.show();
}
最佳答案
尝试将您的起始代码更改为:
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
也不要在尝试将其更改为此后调用 return:
dialog.dismiss();
调用 return 可能会关闭您的 Activity。
关于android - Intent 打开 GPS 并返回应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33172855/