0

问题:在 Google 地图上启用了 MyLocationButton 并且 GPS 已关闭。当用户点击它时,它只是默默地失败。这是一个非常糟糕的用户交互。我希望它提示用户更改 GPS 设置(就像它在谷歌地图上实际所做的那样)。

看来我可以重新定义按钮的处理程序,但我喜欢等待用户位置和居中地图部分(并且很乐意避免重写它)。有没有办法捕捉按钮失败事件?

谢谢。

4

1 回答 1

-1

我认为这将通过检查 GPS 是否启用并在禁用时提醒用户来解决。我从这个链接复制了代码。

final LocationManager manager = (LocationManager) getSystemService( Context.LOCATION_SERVICE );

    if ( !manager.isProviderEnabled( LocationManager.GPS_PROVIDER ) ) {
        buildAlertMessageNoGps();
    }

private void buildAlertMessageNoGps() {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Your GPS seems to be disabled, do you want to enable it?")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                   startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS));
               }
           })
           .setNegativeButton("No", new DialogInterface.OnClickListener() {
               public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
                    dialog.cancel();
               }
           });
    final AlertDialog alert = builder.create();
    alert.show();
}
于 2017-02-05T22:59:13.410 回答