Calling startIntentSenderForResult from Fragment (Android Billing v3)

前端 未结 11 1146
广开言路
广开言路 2020-11-29 02:46

The new Android Billing v3 documentation and helper code uses startIntentSenderForResult() when launching a purchase flow. I want to start a purchase flow (and

11条回答
  •  失恋的感觉
    2020-11-29 03:27

    You need to pass fragment and data to parent activity, then call fragment onActivityResult from the parent activity.

    like this

    in fragment:

    HomeActivity activity = (HomeActivity) getActivity();
    activity.purchaseLauncher(this, mHelper, productDTO.getSku(), RC_REQUEST, mPurchaseFinishedListener, PAYLOAD);

    in parent activity:

    @Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            if (storeFragment != null) {
                storeFragment.onActivityResult(requestCode, resultCode, data);
            }
        }
    
        public void purchaseLauncher(StoreFragment storeFragment, IabHelper mHelper, String sku, int requestCode, IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener, String payload) {
            this.storeFragment = storeFragment;
            mHelper.launchPurchaseFlow(this, sku, requestCode, mPurchaseFinishedListener, payload);
        }

提交回复
热议问题