我如何在Android中更改位置设置而不必手动进行设置?
我想使用谷歌地图功能询问用户是否想要打开wifi、位置(或更改模式),而不需要进入用户必须手动更改的设置 以下是我希望通过编程方式执行的一些示例:我如何在Android中更改位置设置而不必手动进行设置?,android,google-maps,settings,Android,Google Maps,Settings,我想使用谷歌地图功能询问用户是否想要打开wifi、位置(或更改模式),而不需要进入用户必须手动更改的设置 以下是我希望通过编程方式执行的一些示例: 如果谷歌地图有它,这应该是可能的。您可以编写代码,在地图活动的顶部显示警报对话框。以下是一个例子: AlertDialog.Builder alertDialog = new AlertDialog.Builder( this); // Setting Dialog Title alertDialog.s
如果谷歌地图有它,这应该是可能的。您可以编写代码,在地图活动的顶部显示警报对话框。以下是一个例子:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
this);
// Setting Dialog Title
alertDialog.setTitle("Confirm...");
// Setting Dialog Message
alertDialog.setMessage("Do you want to go to wifi settings?");
// Setting Icon to Dialog
// alertDialog.setIcon(R.drawable.ic_launcher);
// Setting Positive "Yes" Button
alertDialog.setPositiveButton("yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Activity transfer to wifi settings
startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
}
});
// Setting Negative "NO" Button
alertDialog.setNegativeButton("no",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to invoke NO event
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
代码是自解释的。
希望这有帮助 “如果谷歌地图拥有它,这应该是可能的”——严格来说,这不是真的,因为谷歌地图是一个系统应用程序,因此可以做普通SDK应用程序无法做的事情。在这种情况下,虽然Maps已经能够做到这一点有一段时间了,但只有当新的Play Services 7.0 SDK可用时,我们才能使用它:我已将您的屏幕截图添加到问题本身,并删除了干扰词(“谢谢”)。这正是我当前的解决方案:)您可以接受此解决方案,以便其他人也可以参考此解决方案!!谢谢