【问题标题】:Cannot to connect to Google API Client, GooglePlayServices无法连接到 Google API 客户端、GooglePlayServices
【发布时间】:2018-02-18 10:45:40
【问题描述】:

我正在尝试使用 Google Play 服务,尤其是游戏 API,但我一直坚持这一点。

我已经配置并编译了来自 Google 的两个示例并在我的设备上运行。它们都运行良好,成就、排行榜都是我在 Google 控制台上配置的。

所以我想更进一步,从头开始使用 GPServices 制作我自己的应用程序。使用最新的稳定版 Android Studio 2.3.3 和最新的 SDK

我创建了一个新项目,配置为 Google 指南和示例。

Android 清单:

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <meta-data android:name="com.google.android.gms.games.APP_ID"
            android:value="@string/app_id" />
        <meta-data android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version"/>

        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "playservices.workshop.akbolatss.gplayservices"
        minSdkVersion 22
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.+'

    compile "com.google.android.gms:play-services-games:11.0.4"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
}

还有MainActivity

public class MainActivity extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {

    GoogleApiClient googleApiClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

        googleApiClient.connect();
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        Toast.makeText(this, "onConnected", Toast.LENGTH_LONG).show();
        Log.d("TAG", "onConnected");
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d("TAG", "onConnectionSuspended");
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Toast.makeText(this, "onConnectionFailed " + connectionResult.getResolution() + " " + connectionResult.getErrorMessage(), Toast.LENGTH_LONG).show();
        Log.d("TAG", "onConnectionFailed");
    }
}

问题是它 100% 失败。日志永远不会告诉你出了什么问题。我不知道我错过了哪里,这看起来像是在浪费时间。如果你有时间,请检查项目,mby 它在我的机器上特别不起作用

项目链接:https://www.dropbox.com/s/h6wsqlvnhno60g8/GPlayServices.rar?dl=0

示例链接:https://github.com/playgameservices/android-basic-samples

【问题讨论】:

  • 您是否在 google 开发者控制台中配置了项目,为 auth2.0 提供了 SHA-1 密钥,最后您是否已将开发者控制台中的应用程序 ID 添加到您的 ids.xml 或 strings.xml 文件中?
  • 是的,我做了这些步骤。当我调用 googleApi.connect() 方法时仍然没有任何反应
  • 您是否也在开发者 conaole 的测试帐户中添加了您的电子邮件?

标签: android android-studio google-api google-play-services google-play-games


【解决方案1】:

您是否获得了用于访问 API 的特定密钥?

【讨论】:

  • 不,我没有,在清单里面我已经声明了它
猜你喜欢
  • 2016-12-08
  • 2015-08-19
  • 1970-01-01
  • 2018-03-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-06-06
  • 2022-10-20
相关资源
最近更新 更多