diff options
author | Xavier Sellier <xsellier@gmail.com> | 2018-02-12 11:33:15 -0500 |
---|---|---|
committer | RĂ©mi Verschelde <rverschelde@gmail.com> | 2018-02-14 08:05:19 +0100 |
commit | b8def58705148858c565ccd63d0c1a87c52e23d3 (patch) | |
tree | 8364324853e4f61b7c4a433c4966f6a69bf0ed36 /platform/android/java/src/org | |
parent | ac5cce5e9513eba34745f7e1e90c320ec92390f9 (diff) |
Add signals and a check function for Android service connectivity.
- Add a iap_connect and iap_disconnect events for android platform.
- Add isConnected() function returning true if its connected to android service, false otherwise
(cherry picked from commit 546b48813f2b75481d846957275f6d4eecd8de3c)
Diffstat (limited to 'platform/android/java/src/org')
-rw-r--r-- | platform/android/java/src/org/godotengine/godot/GodotPaymentV3.java | 15 | ||||
-rw-r--r-- | platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java | 14 |
2 files changed, 28 insertions, 1 deletions
diff --git a/platform/android/java/src/org/godotengine/godot/GodotPaymentV3.java b/platform/android/java/src/org/godotengine/godot/GodotPaymentV3.java index 6b7f7a283e..d72c590378 100644 --- a/platform/android/java/src/org/godotengine/godot/GodotPaymentV3.java +++ b/platform/android/java/src/org/godotengine/godot/GodotPaymentV3.java @@ -67,7 +67,7 @@ public class GodotPaymentV3 extends Godot.SingletonBase { public GodotPaymentV3(Activity p_activity) { - registerClass("GodotPayments", new String[] { "purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails" }); + registerClass("GodotPayments", new String[] { "purchase", "setPurchaseCallbackId", "setPurchaseValidationUrlPrefix", "setTransactionId", "getSignature", "consumeUnconsumedPurchases", "requestPurchased", "setAutoConsume", "consume", "querySkuDetails", "isConnected" }); activity = (Godot)p_activity; mPaymentManager = activity.getPaymentsManager(); mPaymentManager.setBaseSingleton(this); @@ -164,6 +164,19 @@ public class GodotPaymentV3 extends Godot.SingletonBase { GodotLib.calldeferred(purchaseCallbackId, "has_purchased", new Object[] { receipt, signature, sku }); } + public void callbackDisconnected() { + GodotLib.calldeferred(purchaseCallbackId, "iap_disconnected", new Object[]{}); + } + + public void callbackConnected() { + GodotLib.calldeferred(purchaseCallbackId, "iap_connected", new Object[]{}); + } + + // true if connected, false otherwise + public boolean isConnected() { + return mPaymentManager.isConnected(); + } + // consume item automatically after purchase. default is true. public void setAutoConsume(boolean autoConsume) { mPaymentManager.setAutoConsume(autoConsume); diff --git a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java index da6d66ae88..441a311358 100644 --- a/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java +++ b/platform/android/java/src/org/godotengine/godot/payments/PaymentsManager.java @@ -93,11 +93,21 @@ public class PaymentsManager { @Override public void onServiceDisconnected(ComponentName name) { mService = null; + + // At this stage, godotPaymentV3 might not have been initialized yet. + if (godotPaymentV3 != null) { + godotPaymentV3.callbackDisconnected(); + } } @Override public void onServiceConnected(ComponentName name, IBinder service) { mService = IInAppBillingService.Stub.asInterface(service); + + // At this stage, godotPaymentV3 might not have been initialized yet. + if (godotPaymentV3 != null) { + godotPaymentV3.callbackConnected(); + } } }; @@ -123,6 +133,10 @@ public class PaymentsManager { .purchase(sku, transactionId); } + public boolean isConnected() { + return mService != null; + } + public void consumeUnconsumedPurchases() { new ReleaseAllConsumablesTask(mService, activity) { |