我有一个应用程序,几乎总是需要知道用户的位置.
当我需要访问某个位置时,我这样做:
final AlertDialog.Builder builder = new AlertDialog.Builder( MapScreen.this); builder.setTitle("MyAppName"); builder.setMessage("The location service is off. Do you want to turn it on?"); builder.setPositiveButton("Enable location",new DialogInterface.OnClickListener() { @Override public void onClick( final DialogInterface dialogInterface,final int i) { startActivity(new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); builder.setNegativeButton("Continue without location",null); builder.create().show();
然而,GPS给了我一些不够精确的信息. Wi-Fi总是给我足够的准确性,所以我想要求用户打开Wi-Fi,就像我要求他们打开位置一样.我不想只是打开它,我希望用户得到通知,并手动启用它.
解决方法@H_502_12@
以下意图显示了无线设置,如Wi-Fi,蓝牙和移动网络:
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
有关设置的完整列表:https://developer.android.com/reference/android/provider/Settings.html
有关startActivity方法的文档:
https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)
(请记住,startActivity只是扔掉而忘记,如果你想捕获用户所做的响应,你可以调用startActivityForResult,在这种情况下可能不需要)
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
有关设置的完整列表:https://developer.android.com/reference/android/provider/Settings.html
有关startActivity方法的文档:
https://developer.android.com/reference/android/app/Activity.html#startActivity(android.content.Intent)
(请记住,startActivity只是扔掉而忘记,如果你想捕获用户所做的响应,你可以调用startActivityForResult,在这种情况下可能不需要)