我为Android编写了一个程序。在Google Play控制台中,我启用了Google Play服务。在程序中我想连接到它们。在Google Play Developer控制台中,我已将我的帐户添加到测试中。服务GooglePlay已发布。很遗憾,我无法连接到Google Play服务。我总是收到消息"没有连接"。我的程序中有什么问题,或者我在Google Play控制台中设置错误了吗? 我附加了" manifest.xml"的片段,活动文本和Google控制台的屏幕截图。
请帮帮我!我根据Google Play上的说明做了一切,但是从两周后我找不到解决方案。
问候,gravedg
文件片段" Manifest.xml ":
<meta-data android:name="com.google.android.gms.games.APP_ID" (my app ID is here) android:value="@string/app_id" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
文件碎片&#34; Test1Activity.java &#34;:
package pl.(... here is my package name ...);
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Toast;
topublic class Test1Activity extends AppCompatActivity
implements ConnectionCallbacks, OnConnectionFailedListener {
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API)
.addScope(Games.SCOPE_GAMES)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
@Override
public void onConnected(Bundle connectionHint) {
Toast.makeText(getApplicationContext(), "Connection OK", Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionSuspended(int cause) {
Toast.makeText(getApplicationContext(), "Connection Suspended", Toast.LENGTH_LONG).show();
}
@Override
public void onConnectionFailed(ConnectionResult result) {
Toast.makeText(getApplicationContext(), "No connection", Toast.LENGTH_LONG).show();
}
答案 0 :(得分:1)
如文档中所示:客户端可以选择在不使用API的情况下继续,也可以调用startResolutionForResult(Activity,int)来提示用户登录。
尝试使用startResolutionForResult()
这样的函数登录:
@Override
public void onConnectionFailed(ConnectionResult result) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
mConnectionResult = result;
}