简体   繁体   English

Google Play说要登录Google帐户(应用内结算)

[英]Google Play says to sign into Google account (In-app billing)

I've been trying to solve this problem for a week and I've no any success. 我已经尝试解决这个问题了一个星期,但没有任何成功。 The thing is that, I handle if the user of the app tries to buy subscription without being signed into Google account and I lead him to Google sign in screen, but even after user has signed in and tries to buy subscription Google play says he needs to sign into Google account. 事实是,如果该应用程序的用户尝试购买订阅但未登录Google帐户并导致他进入Google登录屏幕,但即使在用户登录并尝试购买订阅后,我仍会处理,Google Play表示他需要登录Google帐户。 On this very step I've been debugging and AccountManager's getAccounts() returns array including account that has been recently added by the user. 在这一步中,我一直在调试,并且AccountManager的getAccounts()返回包含用户最近添加的帐户的数组。 And only after I kill the app and launch it again, Google play sees user's Google account and purchase works fine. 而且只有在我终止该应用程序并再次启动它之后,Google Play才会看到用户的Google帐户和购买正常。 Any ideas how to fix this problem? 任何想法如何解决此问题? Here is the method which is called when the user clicks "Purchase" button: 这是用户单击“购买”按钮时调用的方法:

accountsArray = accountManager.getAccountsByType("com.google");
   if(accountsArray != null && accountsArray.length >= 1){
       SystemUtils.getCache(this, new CacheUtils.CallBack<Cache>() {
           @Override
           public void run(Cache cache) {
               billingActivityCache = cache;
           }
       });

       JSONObject payload = null;
       try {
           payload = new JSONObject()
                   .put("user", new JSONObject()
                           .put("id", billingActivityCache.getUser().getId()
                           ));
       } catch (JSONException e) {
           e.printStackTrace();
       }

       Bundle buyIntentBundle = null;
       try {
           buyIntentBundle = mService.getBuyIntent(3, getPackageName(),
                   currentSku, "subs", payload.toString());
       } catch (RemoteException e) {
           e.printStackTrace();
       }

       PendingIntent pendingIntent = buyIntentBundle.getParcelable("BUY_INTENT");
       try {
           startIntentSenderForResult(pendingIntent.getIntentSender(),
                   BUY_KEY, new Intent(), Integer.valueOf(0), Integer.valueOf(0),
                   Integer.valueOf(0));
       } catch (IntentSender.SendIntentException e) {
           e.printStackTrace();
       }
   } else{
       Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
       intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES, new String[]{"com.google"});
       startActivityForResult(intent, LOGIN_GOOGLE);
   }

(Not a part of answer but) (不是答案的一部分,但是)
First, do NOT put personal info in plane text as a bundle. 首先,请勿将个人信息作为捆绑放在平面文字中。
User id is a personal info. 用户ID是个人信息。
Check Google privacy policy. 查看Google隐私权政策。


Related Q&A here. 相关问答。 [Change Gmail account to make in-app purchase?] https://android.stackexchange.com/questions/70215/change-gmail-account-to-make-in-app-purchase [更改Gmail帐户以进行应用内购买?] https://android.stackexchange.com/questions/70215/change-gmail-account-to-make-in-app-purchase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM