使用最新的android sdk我正在为android marketplace构建一个应用程序。我需要登录才能为我的游戏排行榜和成就提供服务。 我有两个活动。我在第一个活动中加载播放服务,如果在第二个活动中连接,我可以访问它,我相信。
使用我当前的代码,它会尝试连接到Google Play服务,但会陷入导致其尝试永久循环的处理程序中。注释部分,它尝试登录一次然后停止。所以这就是我对发布活动的看法:
这是我的Android Manifest文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androd="http://schemas.android.com/apk/res-auto"
package="com.my.application.name"
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Add the following meta-data for devices running Google Play service. -->
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<meta-data
android:name="com.google.android.gms.games.APP_ID"
android:value="@string/app_id"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
另外,这是我的开场画面:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
public class openingScreen extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener {
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 10004;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
/* A flag indicating that a PendingIntent is in progress and prevents
* us from starting further intents.
*/
private boolean mIntentInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opening_screen);
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
...
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(getApplicationContext(), "Welcome Back, To the Stage of History ", Toast.LENGTH_SHORT).show();
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
mGoogleApiClient.connect();
} else if (view.getId() == R.id.sign_out_button) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
result.startResolutionForResult(this, // your activity
RC_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
Log.e("network", "onConnectionFailed: "+ String.valueOf(e));
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
Log.e("network", "forever connecting loop Failed: " + requestCode + " "+ intent);
// mGoogleApiClient.connect();
}
}
}
}
请记住,我还做了以下事情:
该应用尝试登录Google Play服务,然后触发activityResult()回调:
查看我过去的logcat文件,跟踪显示403错误Google Game Services Not Configured。正如我们可以从我的代码中看到的那样,堆栈给出了一个未找到客户端ID的响应,但它在game-ids.xml中就像谷歌播放api文档所说的那样!
我已经选择了这个太久了,这似乎并不重要,因为我小心地只输入生成发布创建的apk的生成的sha1键。 Stack Overflow,请帮助。
07-26 17:18:48.224 5126-4861 /? E / SignInIntentService:未配置访问权限。您的项目未启用API(Google Play游戏服务API)。请使用Google Developers Console更新您的配置。 com.google.android.gms.games.server.error.GamesException 在com.google.android.gms.games.server.GamesServer.getResponseBlocking(GamesServer.java:156) 在com.google.android.gms.games.broker.PlayerAgent.getPlayerFromNetwork(PlayerAgent.java:1737) 在com.google.android.gms.games.broker.PlayerAgent.fetchPlayer(PlayerAgent.java:623) 在com.google.android.gms.games.broker.DataBroker.loadSelf(DataBroker.java:828) 在com.google.android.gms.games.service.PlayGamesSignInIntentService $ LoadSelfOperation.executeInternal(PlayGamesSignInIntentService.java:366) 在com.google.android.gms.games.service.PlayGamesSignInIntentService $ BaseOperation.execute(PlayGamesSignInIntentService.java:52) 在com.google.android.gms.games.service.PlayGamesSignInIntentService $ OperationAdapter.execute(PlayGamesSignInIntentService.java:451) 在com.google.android.gms.chimera.BaseAsyncOperationService $ OperationTask.run(BaseAsyncOperationService.java:179) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:573) 在java.lang.Thread.run(Thread.java:841) 07-26 17:18:48.234 32016-32016 /? E / LoadSelfFragment:无法登录 - 应用程序没有已注册的客户端ID
答案 0 :(得分:1)
罪魁祸首是我被迫只为其签名版本。我无法使用在我的设备上生成的开发人员构建。使用Android文件传输并使用应用程序设置菜单手动卸载我的设备允许我安装已签名的版本。安装签名版本并上传到Play开发者控制台似乎允许我登录!
我也意识到我的做法是徒劳的。事实证明,我似乎无法将我从活动到活动的连接延续下去,就像我曾经想过的那样。我现在正在重构我的代码以处理活动,因为我似乎无法克服可见性:消失或可见:正确处理点击事件。