From d8930ba1591d48e19b0a3740e95bead8d7dc759f Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Tue, 8 Dec 2020 16:32:41 +0000 Subject: [PATCH] Add Android deep linking support in PushNotifications class --- .../native/juce_android_PushNotifications.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp index ae2f503f790d..cf062468efba 100644 --- a/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp +++ b/modules/juce_gui_extra/native/juce_android_PushNotifications.cpp @@ -1547,6 +1547,39 @@ struct PushNotifications::Pimpl && env->CallBooleanMethod (extras, AndroidBundle.containsKey, javaString ("google.message_id").get()); } + static bool isBrowsableNotificationIntent (jobject intent) + { + auto* env = getEnv(); + + auto intentAction = juceString ((jstring) env->CallObjectMethod (intent, AndroidIntent.getAction)); + + auto isView = intentAction == "android.intent.action.VIEW"; + + auto categories = LocalRef (env->CallObjectMethod (intent, AndroidIntent.getCategories)); + + int categoriesNum = categories != nullptr + ? env->CallIntMethod (categories, JavaSet.size) + : 0; + + if (categoriesNum == 0) + return false; + + if (! env->CallBooleanMethod (categories, JavaSet.contains, javaString ("android.intent.category.BROWSABLE").get())) + return false; + + return isView; + } + + static void callAnotherInstanceStartedWithIntentURI (jobject intent) + { + auto* env = getEnv(); + + auto intentDataUri = LocalRef (env->CallObjectMethod (intent, AndroidIntent.getData)); + auto intentDataString = juceString ((jstring) env->CallObjectMethod (intentDataUri, AndroidUri.toString)); + + JUCEApplication::getInstance()->anotherInstanceStarted (intentDataString); + } + PushNotifications& owner; }; @@ -1632,6 +1665,10 @@ bool juce_handleNotificationIntent (void* intent) return true; } + else if (PushNotifications::Pimpl::isBrowsableNotificationIntent ((jobject) intent)) + { + return true; + } #if defined(JUCE_FIREBASE_MESSAGING_SERVICE_CLASSNAME) else if (PushNotifications::Pimpl::isRemoteNotificationIntent ((jobject) intent)) {