【问题标题】:Sometime my button is not working in my app有时我的按钮在我的应用程序中不起作用
【发布时间】:2015-03-27 09:35:33
【问题描述】:

我正在单击按钮检查 GPS 是否已启用,有时 GPS 已启用,此时我的按钮也不起作用。如果我关闭 GPS 并再次手动打开 GPS,那么它就可以工作了。

我该如何解决这个问题?

这是我的 GPS 代码

/*
 * checking gps is available or not in android device.
 */
@SuppressWarnings("deprecation")
public boolean isGPSAvailable() {
    ContentResolver contentResolver = getBaseContext().getContentResolver();
    boolean isGPSOn = Settings.Secure.isLocationProviderEnabled(
            contentResolver, LocationManager.GPS_PROVIDER);
    if (!isGPSOn) {
        new DialogHelper(this, R.string.title_err_attention,
                R.string.msg_err_nogps, R.string.txt_settings,
                R.string.txt_exit, new DialogCallBack() {

                    @Override
                    protected void onPositiveBtnClick() {
                        // TODO Auto-generated method stub
                        super.onPositiveBtnClick();
                        Intent settings = new Intent(
                                Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(settings);
                        Home.this.finish();
                    }

                    @Override
                    protected void onNegativeBtnClick() {
                        // TODO Auto-generated method stub
                        super.onNegativeBtnClick();
                        Home.this.finish();
                    }
                }).show();
    }

    return isGPSOn;
}

【问题讨论】:

  • 你有代码吗> 贴出来
  • 显示你的逻辑是如何确保在代码中启用 GPS
  • 我已经发布了我的代码@MD

标签: android gps android-button


【解决方案1】:

使用类似的布尔值: isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

【讨论】:

    【解决方案2】:

    我制作了一种检查 GPS 状态的方法。它可能会帮助你。

    public static boolean isGpsAvailable(Context context) {
                LocationManager manager = (LocationManager) context
                        .getSystemService(Context.LOCATION_SERVICE);
                boolean statusOfGPS = manager
                        .isProviderEnabled(LocationManager.GPS_PROVIDER);
                return statusOfGPS;
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多