2015-12-15 87 views
2

我爲Android編寫了一個程序。在Google Play控制檯中,我已啓用Google Play服務。在我想要連接到他們的程序中。在Google Play開發者控制檯中,我已將我的帳戶添加到測試中。服務GooglePlay已發佈。很遺憾,我無法連接到Google Play服務。我總是收到消息「無連接」。我的程序中是否有問題,或者我在Google Play控制檯中設置了錯誤? 我附加了「manifest.xml」的片段,活動文本和Google控制檯的屏幕截圖。無法連接到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" /> 

片段文件的「 Test1Activity.java」:

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(); 
} 

Google Developer Console - services enabled

Google Play Developer Console - services published

回答

1

如文檔,請參見:客戶可以選擇繼續不使用API​​,或者它可以調用startResolutionForResult(活動,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; 
} 
+1

太棒了!有用。非常感謝您的回答,jlopez。 :) – gravedg

+0

我很樂意幫助你,所以如果答案幫助你,你能把它標記爲正確嗎? – jlopez

+0

要做到這一點,我需要15點的聲望。目前我有11分。我會記住的。我會盡可能標記它。 – gravedg

相關問題