- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Google Play 游戏服务制作简单的游戏,但未能登录 Google Play 游戏。
我得到这个错误:
登录失败。请检查您的网络连接并重试。
我有 MainActivity 和三个 fragment 网(MainFragment、GameFragment 和 ResultFragment)。
MainFragment 是主菜单的 fragment ,其中有按钮可以点击开始游戏。
授权?
我已在 Google Play 开发者控制台中使用 SHA-1 链接并授权我的游戏。
当我使用 Android Studio 时,我的包名称类似于:aplikacijezaandroid.thebuttonchallenge,我在 Google Play 开发者控制台上的链接应用中添加了两个应用版本。
所以我有 com.aplikacijezaandroid.thebuttonchallenge 和 aplikacijezaandorid.thebuttonchallenge
应用 ID?
我将应用程序 ID 和排行榜 ID 添加到 strings.xml 中,并将元标记添加到 Android Manifest。
我在AndroidManifest.xml中添加了上网权限
测试?
我使用物理设备从 Android Studio 测试和调试应用程序,并且在 Google Play 开发者控制台中添加了我自己的 gmail 作为测试用户。
这是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="aplikacijezaandroid.thebuttonchallenge" >
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<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"/>
</application>
这是 MainActivity 类:
public class MainActivity extends Activity implements MainMenuFragment.Listener,
GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
GameFragment.Listener, ResultFragment.Listener {
//Fragments
MainMenuFragment mMainFragment;
GameFragment mGameFragment;
ResultFragment mResultFragment;
// Client used to interact with Google APIs
private GoogleApiClient mGoogleApiClient;
// Are we currently resolving a connection failure?
private boolean mResolvingConnectionFailure = false;
// Has the user clicked the sign-in button?
private boolean mSignInClicked = false;
// Automatically start the sign-in flow when the Activity starts
private boolean mAutoStartSignInFlow = true;
// request codes we use when invoking an external activity
private static final int RC_RESOLVE = 5000;
private static final int RC_UNUSED = 5001;
private static final int RC_SIGN_IN = 9001;
//Debug
private String TAG = "IGRA";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 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();
//Fragments
mMainFragment = new MainMenuFragment();
mGameFragment = new GameFragment();
mResultFragment = new ResultFragment();
// listen to fragment events
mMainFragment.setListener(this);
mGameFragment.setListener(this);
mResultFragment.setListener(this);
//Treba dodati listenere
// add initial fragment (welcome fragment)
if (savedInstanceState == null) {
getFragmentManager().beginTransaction().add(R.id.container, mMainFragment).commit();
}
}
// Switch UI to the given fragment
void switchToFragment(Fragment newFrag) {
getFragmentManager().beginTransaction().replace(R.id.container, newFrag)
.commit();
}
private boolean isSignedIn() {
return (mGoogleApiClient != null && mGoogleApiClient.isConnected());
}
@Override
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart(): connecting");
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop(): disconnecting");
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onStartGameRequested() {
startGame();
}
@Override
public void onShowAchievementsRequested() {
}
@Override
public void onShowLeaderboardsRequested() {
}
void startGame(){
switchToFragment(mGameFragment);
}
public void onEnteredScore(int finalScore){
mResultFragment.setFinalScore(finalScore);
// push those accomplishments to the cloud, if signed in
pushAccomplishments(finalScore);
// switch to the exciting "you won" screen
switchToFragment(mResultFragment);
}
private void pushAccomplishments(int finalScore) {
if (!isSignedIn()) {
// can't push to the cloud, so save locally
// mOutbox.saveLocal(this);
Log.d(TAG, "can't push to the cloud, so save locally");
return;
}
Games.Leaderboards.submitScore(mGoogleApiClient, getString(R.string.number_guesses_leaderboard),
finalScore);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onConnected(Bundle bundle) {
Log.d(TAG, "onConnected(): connected to Google APIs");
// Show sign-out button on main menu
//mMainFragment.setShowSignInButton(false);
// Show "you are signed in" message on win screen, with no sign in button.
//mWinFragment.setShowSignInButton(false);
// Set the greeting appropriately on main menu
Player p = Games.Players.getCurrentPlayer(mGoogleApiClient);
String displayName;
if (p == null) {
Log.w(TAG, "mGamesClient.getCurrentPlayer() is NULL!");
displayName = "???";
} else {
displayName = p.getDisplayName();
}
mMainFragment.setGreeting("Hello, " + displayName);
// if we have accomplishments to push, push them
/*if (!mOutbox.isEmpty()) {
pushAccomplishments();
Toast.makeText(this, getString(R.string.your_progress_will_be_uploaded),
Toast.LENGTH_LONG).show();
}*/
}
@Override
public void onWinScreenDismissed() {
switchToFragment(mMainFragment);
}
@Override
public void onWinScreenSignInClicked() {
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (requestCode == RC_SIGN_IN) {
mSignInClicked = false;
mResolvingConnectionFailure = false;
if (resultCode == RESULT_OK) {
mGoogleApiClient.connect();
} else {
BaseGameUtils.showActivityResultError(this, requestCode, resultCode,
R.string.signin_failure, R.string.signin_other_error);
}
}
}
@Override
public void onConnectionSuspended(int i) {
Log.d(TAG, "onConnectionSuspended(): attempting to connect");
mGoogleApiClient.connect();
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d(TAG, "onConnectionFailed(): attempting to resolve");
if (mResolvingConnectionFailure) {
Log.d(TAG, "onConnectionFailed(): already resolving");
return;
}
if (mSignInClicked || mAutoStartSignInFlow) {
mAutoStartSignInFlow = false;
mSignInClicked = false;
mResolvingConnectionFailure = true;
if (!BaseGameUtils.resolveConnectionFailure(this, mGoogleApiClient, connectionResult,
RC_SIGN_IN, getString(R.string.signin_other_error))) {
mResolvingConnectionFailure = false;
}
}
// Sign-in failed, so show sign-in button on main menu
mMainFragment.setGreeting(getString(R.string.signed_out_greeting));
//mMainMenuFragment.setShowSignInButton(true);
// mWinFragment.setShowSignInButton(true);
}
最佳答案
我已经解决了这个问题,所以我会发布答案。
我已将应用程序 ID 和排行榜 ID 从 strings.xml 移动到 values 文件夹中的 ids.xml。
我已经删除了所有客户端 ID,并再次为调试 keystore 和发布 keystore 添加了客户端 ID。
关于java - 登录失败。请检查您的网络连接,然后重试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26804929/
我试图通过屏幕截图捕获带有突出显示的元素,但在屏幕截图中,该元素不带有突出显示。有谁知道解决办法吗?当我捕获文本时会出现突出显示:automatests@gmail.com 查看我的代码: Utili
大家好,我是编码的新手,我正在和一位老师一起上 Java 入门课,希望您已经了解一切。我必须对冰雹序列进行编码,它表示为: 选择一些正整数并将其命名为 n。如果 n 是偶数,则将其除以二。如果 n 是
如果存在名称相同的SCOM组,则尝试制作一个请求更多信息(组ID)的脚本: function myFunction { [CmdletBinding()] Param(
我有这张表: id | CUPNAME | FRENCHNAME 1 | 2 | null 2 | null | 4 我想从非空的 CUPNAME 和 FRENCHNAME 中提
我是 Collection View 的新手,想知道这是否是创建它们的最佳方式,我还想了解一些关于从哪里转到启用分页的详细 View 的建议。 #import "MarbleCollectionVie
好的,这是非常好的 jquery slider 。 http://srobbin.com/jquery-plugins/pageslide 我所做的是 http://mbu.mn/test 问题来了。
...有人可以解释一下区别吗? 我在命令提示符下输入的内容: sys.path.append('M:/PythonMods') import qrcode myqr = qrcode.make("ra
我不时在我的服务器上运行 bash 脚本,我正在尝试编写一个脚本来监视日志文件夹并在文件夹超出定义的容量时压缩日志文件。我知道有更好的方法来做我目前正在尝试做的事情,非常欢迎您提出建议。下面的脚本抛出
我是 Groovy & Grails 的新手,我觉得事情不必那么难看……那么我怎样才能让这段代码更好看呢? 这是一个 Grails Controller 类,去掉了一些无趣的部分。尽量不要太挂断我的
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 7年前关闭。 Improve this questi
在这个查询中,除了 5 个连接表之外,我试图使用第 6 个表“Days”将值与连接中的三个表进行比较。但它给了我错误,我不能在连接中使用子查询。 select a.ID, a.Name, a.AMT,
我不想通过 Xpath 提取,我想要更清晰的代码。谢谢我的世界兄弟 来自 Xpath,好的!! Assert.assertEquals("Digite um e-mail ou número de t
这个问题已经有答案了: Google Map is not loading due to inflate exception (3 个回答) 已关闭 9 年前。 我知道有很多关于此的帖子,但我就是无法
我的问题.. a.) 使用内存分配创建一个 float 组来存储 GPA 分数10名学生。为其分配值(您的选择) b.) 找出该数组中的最大 GPA。 c.) 将此数组的内容写入文件 alloc.tx
我最近要制作 Sequelize 。 我有 2 个表,data_track 和 car_detail。我想尝试关联那 2 个表,但它从未关联过。 总是返回错误SequelizeEagerLoading
我有一些代码在 LINQ 中根本无法工作的问题,但它确实可以作为一个简单的 for..each 工作。任何解释和解决方案将不胜感激。 我有 3 个类,Users、User 和 UserPermissi
我正在设计我的第一个大型数据库,并想检查我是否可以提供表关系。 我正在设计一个网络应用程序,其中 用户可以在团队中玩游戏 每个游戏都有其类别 用户为游戏创建他们的团队并选择他们的团队类别 每个游戏都启
我很抱歉成为一个 CSS 菜鸟,希望有人能指导我正确的方向。 我需要帮助的网页可以在 http://filefx.com 找到 当您点击该页面时,您会注意到“选择文件”图标和“上传文件”图标不在同一行
我已经尝试过这个我在网上找到的演示代码练习并创建了这个 slider ,使用滚动条更容易获得它,因为它们已经是为此制作的脚本。现在我正在尝试修改此脚本及其 css,以将滚动条更改为左右两侧的箭头。我已
最近我对 CSS 很感兴趣。学习不同的东西。 我正在尝试像这样放置三个 div: http://i.stack.imgur.com/miN9G.png 我得到的: http://i.stack.img
我是一名优秀的程序员,十分优秀!