From 284308069023a040c6181d92d8d17a878793decc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ritzl?= Date: Mon, 9 Mar 2020 11:22:41 +0100 Subject: [PATCH] Check that the Google Play Store exists on device Fixes #3 --- .../src/java/com/defold/iap/IapGooglePlay.java | 14 ++++++++++++++ game.project | 2 +- main/main.gui_script | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/extension-iap/src/java/com/defold/iap/IapGooglePlay.java b/extension-iap/src/java/com/defold/iap/IapGooglePlay.java index 96aa612..2819f8f 100644 --- a/extension-iap/src/java/com/defold/iap/IapGooglePlay.java +++ b/extension-iap/src/java/com/defold/iap/IapGooglePlay.java @@ -155,10 +155,24 @@ public class IapGooglePlay implements Handler.Callback { this.autoFinishTransactions = autoFinishTransactions; } + private static boolean isPlayStoreInstalled(Context context){ + try { + context.getPackageManager().getPackageInfo("com.android.vending", 0); + return true; + } catch (PackageManager.NameNotFoundException e) { + return false; + } + } + private void init() { // NOTE: We must create Handler lazily as construction of // handlers must be in the context of a "looper" on Android + if (!isPlayStoreInstalled(activity)) { + Log.e(TAG, "Unable to find Google Play Store (com.android.vending)"); + return; + } + if (this.initialized) return; diff --git a/game.project b/game.project index 39c8169..71d0201 100644 --- a/game.project +++ b/game.project @@ -11,7 +11,7 @@ height = 1136 [android] input_method = HiddenInputField package = com.defold.extension.iap -version_code = 3 +version_code = 5 [project] title = extension-iap diff --git a/main/main.gui_script b/main/main.gui_script index 2164817..29ff3fd 100644 --- a/main/main.gui_script +++ b/main/main.gui_script @@ -12,6 +12,7 @@ local items = { SUBSCRIPTION, } +-- mapping between product id and button name local item_buttons = { [GOLDBARS_SMALL] = "goldbars_small", [GOLDBARS_MEDIUM] = "goldbars_medium",