android studio - google play services, resultcode 0 onactivityresult -


i've been trying connect google play services without success. i've been checking keys , id's correct.

but i'm not getting traffic on api manager. on earth problem?

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      log.d(tag, getsha1certfingerprint(this));     log.d(tag, getappidfromresource(this));      mgoogleapiclient = new googleapiclient.builder(this)             .addconnectioncallbacks(this)             .addonconnectionfailedlistener(this)             .addapi(games.api).addscope(games.scope_games)             .build();      textupdate(); }  @override protected void onactivityresult(int requestcode, int resultcode, intent data) {     super.onactivityresult(requestcode, resultcode, data);     log.d(tag, "requestcode " + requestcode + " resultcode " + resultcode);     if (requestcode == rc_sign_in) {         msigninclicked = false;         mresolvingconnectionfailure = false;         if (resultcode == result_ok) {             mgoogleapiclient.connect();         } else {             basegameutils.showactivityresulterror(this, requestcode, resultcode, r.string.signin_other_error);         }     } }  @override public void onbackpressed() {     super.onbackpressed();     finish();     startactivity(new intent(highscore.this,startscreen.class)); }    public void btngooglehigh (view view){     if (issignedin()) {         startactivityforresult(games.leaderboards.getallleaderboardsintent(mgoogleapiclient),                 rc_unused);     } else {         basegameutils.makesimpledialog(this, getstring(r.string.leaderboards_not_available)).show();     } }  public void btnlogin (view view){     msigninclicked = true;     mgoogleapiclient.connect(); } public void btnlogout (view view){     msigninclicked = false;     games.signout(mgoogleapiclient);     if (mgoogleapiclient.isconnected()) {         mgoogleapiclient.disconnect();     } }   @override public void onconnected(@nullable bundle bundle) {     log.d(tag, "onconnected(): connected google apis"); }  @override public void onconnectionsuspended(int i) {     log.d(tag, "onconnectionsuspended(): attempting connect");     mgoogleapiclient.connect(); }  @override public void onconnectionfailed(@nonnull connectionresult connectionresult) {     log.d(tag, "onconnectionfailed(): attempting resolve");     if (mresolvingconnectionfailure) {         log.d(tag, "onconnectionfailed(): 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;         }     } }  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();     } }  static string getappidfromresource(context ctx) {     try {         resources res = ctx.getresources();         string pkgname = ctx.getpackagename();         int res_id = res.getidentifier("app_id", "string", pkgname);         return res.getstring(res_id);     } catch (exception ex) {         ex.printstacktrace();         return "??? (failed retrieve app id)";     } }  static string getsha1certfingerprint(context ctx) {     try {         signature[] sigs = ctx.getpackagemanager().getpackageinfo(                 ctx.getpackagename(), packagemanager.get_signatures).signatures;         if (sigs.length == 0) {             return "error: no signature.";         } else if (sigs.length > 1) {             return "error: multiple signatures";         }         byte[] digest = messagedigest.getinstance("sha1").digest(sigs[0].tobytearray());         stringbuilder hexstring = new stringbuilder();         (int = 0; < digest.length; ++i) {             if (i > 0) {                 hexstring.append(":");             }             bytetostring(hexstring, digest[i]);         }         return hexstring.tostring();      } catch (packagemanager.namenotfoundexception ex) {         ex.printstacktrace();         return "(error: package not found)";     } catch (nosuchalgorithmexception ex) {         ex.printstacktrace();         return "(error: sha1 algorithm not found)";     } } static void bytetostring(stringbuilder sb, byte b) {     int unsigned_byte = b < 0 ? b + 256 : b;     int hi = unsigned_byte / 16;     int lo = unsigned_byte % 16;     sb.append("0123456789abcdef".substring(hi, hi + 1));     sb.append("0123456789abcdef".substring(lo, lo + 1)); } 

try checking documents "troubleshooting issues in android game" , "debugging android games". documents debug , resolve issue encountered in game.

if unable sign players game, first make sure have followed instructions create client ids , configure games services. if still encounter sign-in errors, check following items make sure game set correctly.

  • check metadata tags
  • check package name
  • check certificate fingerprint
  • check test accounts enabled

for code implementation purposes, kindly check samples google. show basic login, multiplayer, cloud saving , more.

hope helps.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -