Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/plugins/iap/src/com/foxdebug/iap/Iap.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.lang.ref.WeakReference;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
Expand All @@ -35,14 +36,14 @@
public class Iap extends CordovaPlugin {

private BillingClient billingClient;
private Context context;
private Activity activity;
private WeakReference<Context> contextRef;
private WeakReference<Activity> activityRef;
private CallbackContext purchaseUpdated;

public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
context = cordova.getContext();
activity = cordova.getActivity();
contextRef = new WeakReference<>(cordova.getContext());
activityRef = new WeakReference<>(cordova.getActivity());
billingClient = getBillingClient();
}

Expand Down Expand Up @@ -103,7 +104,7 @@ public void run() {

private BillingClient getBillingClient() {
return BillingClient
.newBuilder(this.context)
.newBuilder(this.contextRef.get())
.enablePendingPurchases()
.setListener(
new PurchasesUpdatedListener() {
Expand Down Expand Up @@ -248,7 +249,7 @@ private void purchase(String json, CallbackContext callbackContext) {
try {
SkuDetails skuDetails = new SkuDetails(json);
BillingResult result = billingClient.launchBillingFlow(
activity,
activityRef.get(),
BillingFlowParams.newBuilder().setSkuDetails(skuDetails).build()
);
int responseCode = result.getResponseCode();
Expand Down