From b0e2495eac7addd5c005cc5e0d7638e3a670304a Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 19 Dec 2018 10:46:15 +0000 Subject: [PATCH] Android: Updated the code in PushNotifications and InAppPurchases to the recent low-level API changes --- .../native/juce_android_PushNotifications.cpp | 10 ++++---- .../native/juce_android_InAppPurchases.cpp | 25 ++++++++++--------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp index 1af82d3a3d..fffaa11b50 100644 --- a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp +++ b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp @@ -191,7 +191,7 @@ DECLARE_JNI_CLASS_WITH_MIN_SDK (RemoteInputBuilder, "android/app/RemoteInput$Bui //========================================================================== #if defined(JUCE_FIREBASE_INSTANCE_ID_SERVICE_CLASSNAME) - #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ STATICMETHOD (getInstance, "getInstance", "()Lcom/google/firebase/iid/FirebaseInstanceId;") \ METHOD (getToken, "getToken", "()Ljava/lang/String;") @@ -200,7 +200,7 @@ DECLARE_JNI_CLASS_WITH_MIN_SDK (RemoteInputBuilder, "android/app/RemoteInput$Bui #endif #if defined(JUCE_FIREBASE_MESSAGING_SERVICE_CLASSNAME) - #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ STATICMETHOD (getInstance, "getInstance", "()Lcom/google/firebase/messaging/FirebaseMessaging;") \ METHOD (send, "send", "(Lcom/google/firebase/messaging/RemoteMessage;)V") \ METHOD (subscribeToTopic, "subscribeToTopic", "(Ljava/lang/String;)V") \ @@ -209,7 +209,7 @@ DECLARE_JNI_CLASS_WITH_MIN_SDK (RemoteInputBuilder, "android/app/RemoteInput$Bui DECLARE_JNI_CLASS (FirebaseMessaging, "com/google/firebase/messaging/FirebaseMessaging") #undef JNI_CLASS_MEMBERS - #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ METHOD (getCollapseKey, "getCollapseKey", "()Ljava/lang/String;") \ METHOD (getData, "getData", "()Ljava/util/Map;") \ METHOD (getFrom, "getFrom", "()Ljava/lang/String;") \ @@ -223,7 +223,7 @@ DECLARE_JNI_CLASS_WITH_MIN_SDK (RemoteInputBuilder, "android/app/RemoteInput$Bui DECLARE_JNI_CLASS (RemoteMessage, "com/google/firebase/messaging/RemoteMessage") #undef JNI_CLASS_MEMBERS - #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ METHOD (addData, "addData", "(Ljava/lang/String;Ljava/lang/String;)Lcom/google/firebase/messaging/RemoteMessage$Builder;") \ METHOD (build, "build", "()Lcom/google/firebase/messaging/RemoteMessage;") \ METHOD (constructor, "", "(Ljava/lang/String;)V") \ @@ -235,7 +235,7 @@ DECLARE_JNI_CLASS_WITH_MIN_SDK (RemoteInputBuilder, "android/app/RemoteInput$Bui DECLARE_JNI_CLASS (RemoteMessageBuilder, "com/google/firebase/messaging/RemoteMessage$Builder") #undef JNI_CLASS_MEMBERS - #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + #define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ METHOD (getBody, "getBody", "()Ljava/lang/String;") \ METHOD (getBodyLocalizationArgs, "getBodyLocalizationArgs", "()[Ljava/lang/String;") \ METHOD (getBodyLocalizationKey, "getBodyLocalizationKey", "()Ljava/lang/String;") \ diff --git a/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp b/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp index 96ebbac9ad..42c6efcd7a 100644 --- a/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp +++ b/modules/juce_product_unlocking/native/juce_android_InAppPurchases.cpp @@ -27,7 +27,7 @@ namespace juce { -#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ +#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ METHOD (isBillingSupported, "isBillingSupported", "(ILjava/lang/String;Ljava/lang/String;)I") \ METHOD (getSkuDetails, "getSkuDetails", "(ILjava/lang/String;Ljava/lang/String;Landroid/os/Bundle;)Landroid/os/Bundle;") \ METHOD (getBuyIntent, "getBuyIntent", "(ILjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Landroid/os/Bundle;") \ @@ -39,7 +39,7 @@ namespace juce DECLARE_JNI_CLASS (IInAppBillingService, "com/android/vending/billing/IInAppBillingService") #undef JNI_CLASS_MEMBERS -#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ +#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD, CALLBACK) \ STATICMETHOD (asInterface, "asInterface", "(Landroid/os/IBinder;)Lcom/android/vending/billing/IInAppBillingService;") \ DECLARE_JNI_CLASS (IInAppBillingServiceStub, "com/android/vending/billing/IInAppBillingService$Stub") @@ -84,9 +84,10 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, javaString ("com.android.vending.billing.InAppBillingService.BIND").get()); env->CallObjectMethod (intent, AndroidIntent.setPackage, javaString ("com.android.vending").get()); - serviceConnection = GlobalRef (CreateJavaInterface (this, "android/content/ServiceConnection").get()); - android.activity.callBooleanMethod (JuceAppActivity.bindService, intent, - serviceConnection.get(), 1 /*BIND_AUTO_CREATE*/); + serviceConnection = GlobalRef (CreateJavaInterface (this, "android/content/ServiceConnection")); + + env->CallBooleanMethod (getCurrentActivity().get(), AndroidContext.bindService, intent, + serviceConnection.get(), 1 /*BIND_AUTO_CREATE*/); if (threadPool == nullptr) threadPool.reset (new ThreadPool (1)); @@ -98,7 +99,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, if (serviceConnection != nullptr) { - android.activity.callVoidMethod (JuceAppActivity.unbindService, serviceConnection.get()); + getEnv()->CallVoidMethod (getCurrentActivity().get(), AndroidContext.unbindService, serviceConnection.get()); serviceConnection.clear(); } } @@ -144,8 +145,8 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, auto flagsValues = LocalRef (env->CallStaticObjectMethod (JavaInteger, JavaInteger.valueOf, 0)); auto extraFlags = LocalRef (env->CallStaticObjectMethod (JavaInteger, JavaInteger.valueOf, 0)); - android.activity.callVoidMethod (JuceAppActivity.startIntentSenderForResult, intentSender.get(), requestCode, - fillInIntent.get(), flagsMask.get(), flagsValues.get(), extraFlags.get()); + env->CallVoidMethod (getCurrentActivity().get(), AndroidActivity.startIntentSenderForResult, intentSender.get(), requestCode, + fillInIntent.get(), flagsMask.get(), flagsValues.get(), extraFlags.get()); } else if (responseCode == 7) { @@ -325,7 +326,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, //============================================================================== static LocalRef getPackageName() { - return LocalRef ((jstring) (android.activity.callObjectMethod (JuceAppActivity.getPackageName))); + return LocalRef ((jstring) (getEnv()->CallObjectMethod (getAppContext().get(), AndroidContext.getPackageName))); } //============================================================================== @@ -339,7 +340,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, const Callback& callbackToUse) : ThreadPoolJob ("GetProductsInformationJob"), owner (parent), - packageName (packageNameToUse.get()), + packageName (LocalRef (packageNameToUse.get())), productIdentifiers (productIdentifiersToUse), callback (callbackToUse) {} @@ -509,7 +510,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, const Callback& callbackToUse) : ThreadPoolJob ("GetProductsBoughtJob"), owner (parent), - packageName (packageNameToUse.get()), + packageName (LocalRef (packageNameToUse.get())), callback (callbackToUse) {} @@ -631,7 +632,7 @@ struct InAppPurchases::Pimpl : private AsyncUpdater, const Callback& callbackToUse) : ThreadPoolJob ("ConsumePurchaseJob"), owner (parent), - packageName (packageNameToUse.get()), + packageName (LocalRef (packageNameToUse.get())), productIdentifier (productIdentifierToUse), purchaseToken (purchaseTokenToUse), callback (callbackToUse)