【问题标题】:Android: Use Wear API and Games APIAndroid:使用 Wea​​r API 和 Games API
【发布时间】:2016-06-11 12:03:57
【问题描述】:

我有一个 GoogleApiClient。我使用此代码:

GoogleApiClient client = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).addApiIfAvailable(Wearable.API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();

如果用户想连接 Google Play 游戏,我在 SharedPrefs 中存储了一个布尔值。如果是,我打电话给client.connect()。但如果不是我仍然想要,Wearable API 已连接。我怎样才能实现,Wearable API 将始终连接,但 Games API 不连接。

【问题讨论】:

    标签: android wear-os google-play-games google-api-client


    【解决方案1】:

    为什么不简单地根据 SharedPreference 有条件地连接到 Games API?

    GoogleApiClient.Builder bob = new GoogleApiClient.Builder(this)
            .addApiIfAvailable(Wearable.API)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this);
    if (settings.getBoolean("use_games", false)) {
        bob.addApi(Games.API)
                .addScope(Games.SCOPE_GAMES);
    }
    GoogleApiClient client = bob.build();
    

    根据您的问题,这似乎是显而易见的方法。还是我在这里遗漏了什么?

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2017-02-24
      • 2019-06-15
      • 2023-02-04
      • 1970-01-01
      • 2015-10-29
      • 2020-06-25
      • 2021-12-25
      • 2023-04-04
      相关资源
      最近更新 更多