Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Do not register plugin if Activity is null.
  • Loading branch information
juliocbcotta committed Aug 26, 2019
commit 52cd0a0bbaf3f069f1565388adb7b4a141d0f3c9
4 changes: 4 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.1+1

* Android: Do not register if Activity is null.

## 0.2.1

* iOS: Add currencyCode to priceLocale on productDetails.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.android.billingclient.api.BillingClient;
Expand Down Expand Up @@ -67,10 +68,13 @@ static final class MethodNames {

/** Plugin registration. */
public static void registerWith(Registrar registrar) {
final Activity activity = registrar.activity();
if (activity == null) {
return;
}
final MethodChannel channel =
new MethodChannel(registrar.messenger(), "plugins.flutter.io/in_app_purchase");
channel.setMethodCallHandler(
new InAppPurchasePlugin(registrar.context(), registrar.activity(), channel));
channel.setMethodCallHandler(new InAppPurchasePlugin(registrar.context(), activity, channel));
}

public InAppPurchasePlugin(Context context, Activity activity, MethodChannel channel) {
Expand All @@ -80,33 +84,37 @@ public InAppPurchasePlugin(Context context, Activity activity, MethodChannel cha
}

@Override
public void onMethodCall(MethodCall call, Result result) {
public void onMethodCall(MethodCall call, @NonNull Result result) {
final String skuType = call.argument("skuType");
switch (call.method) {
case MethodNames.IS_READY:
isReady(result);
break;
case MethodNames.START_CONNECTION:
startConnection((int) call.argument("handle"), result);
final Integer handle = call.argument("handle");
startConnection(handle, result);
break;
case MethodNames.END_CONNECTION:
endConnection(result);
break;
case MethodNames.QUERY_SKU_DETAILS:
querySkuDetailsAsync(
(String) call.argument("skuType"), (List<String>) call.argument("skusList"), result);
final List<String> skusList = call.argument("skusList");
querySkuDetailsAsync(skuType, skusList, result);
break;
case MethodNames.LAUNCH_BILLING_FLOW:
launchBillingFlow(
(String) call.argument("sku"), (String) call.argument("accountId"), result);
final String sku = call.argument("sku");
final String accountId = call.argument("accountId");
launchBillingFlow(sku, accountId, result);
break;
case MethodNames.QUERY_PURCHASES:
queryPurchases((String) call.argument("skuType"), result);
queryPurchases(skuType, result);
break;
case MethodNames.QUERY_PURCHASE_HISTORY_ASYNC:
queryPurchaseHistoryAsync((String) call.argument("skuType"), result);
queryPurchaseHistoryAsync(skuType, result);
break;
case MethodNames.CONSUME_PURCHASE_ASYNC:
consumeAsync((String) call.argument("purchaseToken"), result);
final String purchaseToken = call.argument("purchaseToken");
consumeAsync(purchaseToken, result);
break;
default:
result.notImplemented();
Expand All @@ -121,7 +129,7 @@ public void onMethodCall(MethodCall call, Result result) {
this.activity = null;
}

private void startConnection(final int handle, final Result result) {
private void startConnection(final Integer handle, final Result result) {
if (billingClient == null) {
billingClient = buildBillingClient(context, channel);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase
description: A Flutter plugin for in-app purchases. Exposes APIs for making in-app purchases through the App Store and Google Play.
author: Flutter Team <[email protected]>
homepage: https://github.com/flutter/plugins/tree/master/packages/in_app_purchase
version: 0.2.1
version: 0.2.1+1


dependencies:
Expand Down