简体   繁体   中英

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. On this very step I've been debugging and AccountManager's getAccounts() returns array including account that has been recently added by the user. And only after I kill the app and launch it again, Google play sees user's Google account and purchase works fine. 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.
Check Google privacy policy.


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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