Guest User

Untitled

a guest
Jun 20th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. BillingClient billingClient = BillingClient.newBuilder(getApplicationContext()).setListener(new PurchasesUpdatedListener() {
  2. @Override
  3. public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
  4. if(responseCode == BillingClient.BillingResponse.OK) {
  5. //Do something
  6. }
  7. }
  8. }).build();
  9. billingClient.startConnection(new BillingClientStateListener() {
  10. @Override
  11. public void onBillingSetupFinished(int responseCode) {
  12. if(responseCode == BillingClient.BillingResponse.OK) {
  13. //Response is OK and working fine
  14. }
  15. }
  16.  
  17. @Override
  18. public void onBillingServiceDisconnected() {
  19. //Do something
  20. }
  21. });
  22.  
  23. billingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
  24. @Override
  25. public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
  26. if(responseCode == BillingClient.BillingResponse.OK) {
  27. //Always returning 0 size() of purchasesList
  28. Toast.makeText(getApplicationContext(), "There are " + purchasesList.size() + " items you've purchased.", Toast.LENGTH_LONG).show();
  29. }
  30. }
  31. });
Add Comment
Please, Sign In to add comment