【发布时间】:2014-08-07 05:20:14
【问题描述】:
如果设备的 GPS 位置被禁用,我将使用以下代码向用户显示一个对话框。
final AlertDialog.Builder builder =
new AlertDialog.Builder(activity);
final String action = Settings.ACTION_LOCATION_SOURCE_SETTINGS;
final String message = "Enable GPS"
+ " service to find current location. And change the location mode to high accuracy for the app to perform accurately. Click OK to go to"
+ " location services settings to let you do so.";
builder.setMessage(message)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
activity.startActivity(new Intent(action));
d.dismiss();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface d, int id) {
d.cancel();
}
});
builder.create().show();
到目前为止,我已经在两台设备 MotoG (v 4.4.4) 和 Samsung duos (v 4.1.2) 上测试了此代码。
我的两台设备都打开了 GPS。 在 MotoG 中,我返回了正确的结果,这是正确的,但在三星设备中,它返回错误。
但是三星设备却返回给我地址(我正在连接到定位服务以获取当前地址)。我在位置客户端的 onConnected 方法中获取地址。如果它返回地址,那么应该启用 GPS 对吗?
为什么有人知道这个问题?
【问题讨论】:
-
可能是因为启用了网络 GPS 但未启用街道精度。