0

我一直在試圖解決這個問題一個星期,我沒有任何成功。問題是,如果應用的用戶嘗試購買訂閱而未登錄Google帳戶,並且我將他引導至Google登錄屏幕,但即使在用戶登錄並嘗試購買訂閱之後,我也會處理Google play說他需要登錄Google帳戶。在這一步我一直在調試和AccountManager的getAccounts()返回數組,包括最近由用戶添加的帳戶。只有當我殺了應用並重新啓動後,Google play纔會看到用戶的Google帳戶和購買工作正常。任何想法如何解決這個問題? 這裏是被稱爲當用戶點擊「購買」按鈕的方法:Google Play說要登錄Google帳戶(應用內結算)

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); 
    } 
+0

顯示該 – AndroidMechanic

+0

的代碼,你可以請出示一些代碼,這@Nataliya –

+0

所以其第二次工作,但不instantly..right –

回答

相關問題