我正在尝试使用Google Play游戏服务制作简单游戏,但我未能登录Google Play游戏.
我收到此错误:
登录失败.请检查您的网络连接,然后重试.
我有MainActivity和三个fragmenets(MainFragment,GameFragment和ResultFragment).
MainFragment是主菜单的片段,使用按钮点击开始游戏.
授权?
我已在Google Play开发者控制台中将我的游戏与SHA-1相关联并授权.
当我使用Android Studio时,我的软件包名称类似于:aplikacijezaandroID.thebuttonchallenge,我在Google Play开发者控制台的链接应用程序中添加了两个应用程序版本.
所以我有com.aplikacijezaandroID.thebuttonchallenge,和aplikacijezaandorID.thebuttonchallenge
应用ID?
我将app ID和leaderboard ID添加到strings.xml中,并将Meta标签添加到AndroID Manifest.
我在AndroIDManifest.xml中添加了Internet权限
测试?
我使用物理设备从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 {//FragmentsMainMenuFragment mMainFragment;GameFragment mGameFragment;ResultFragment mResultFragment;// ClIEnt used to interact with Google Apisprivate 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 startsprivate boolean mautoStartSignInFlow = true;// request codes we use when invoking an external activityprivate static final int RC_RESolVE = 5000;private static final int RC_UNUSED = 5001;private static final int RC_SIGN_IN = 9001;//DeBUGprivate String TAG = "IGRA";@OverrIDeprotected 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 fragmentvoID switchToFragment(Fragment newFrag) { getFragmentManager().beginTransaction().replace(R.ID.container, newFrag) .commit();}private boolean isSignedIn() { return (mGoogleapiclient != null && mGoogleapiclient.isConnected());}@OverrIDeprotected voID onStart() { super.onStart(); Log.d(TAG, "onStart(): connecting"); mGoogleapiclient.connect();}@OverrIDeprotected voID onStop() { super.onStop(); Log.d(TAG, "onStop(): disconnecting"); if (mGoogleapiclient.isConnected()) { mGoogleapiclient.disconnect(); }}@OverrIDepublic voID onStartGameRequested() { startGame();}@OverrIDepublic voID onShowAchIEvementsRequested() {}@OverrIDepublic 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);}@OverrIDepublic 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;}@OverrIDepublic 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);}@OverrIDepublic 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(); }*/}@OverrIDepublic voID onWinScreendismissed() { switchToFragment(mMainFragment);}@OverrIDepublic voID onWinScreenSignInClicked() {}@OverrIDeprotected 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); } }}@OverrIDepublic voID onConnectionSuspended(int i) { Log.d(TAG, "onConnectionSuspended(): attempting to connect"); mGoogleapiclient.connect();}@OverrIDepublic 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);}
解决方法:
我已经解决了这个问题,所以我会发布答案.
我已将values ID和leaderboard ID从strings.xml移到values文件夹中的IDs.xml.
我删除了所有客户端ID,并再次为调试密钥库和发布密钥库添加客户端ID.
总结以上是内存溢出为你收集整理的java – 无法登录.请检查您的网络连接,然后重试全部内容,希望文章能够帮你解决java – 无法登录.请检查您的网络连接,然后重试所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)