ほとんどの場合、ユーザーの場所を知る必要があるアプリがあります。
場所にアクセスする必要があるときは、次のようにします。
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 をオンにするようにユーザーに要求します。オンにするだけではなく、ユーザーに通知して手動で有効にしたいのです。
WiFi メニューをユーザーに提供する意図はありますか?