Skip to content

Commit

Permalink
Add Android deep linking support in PushNotifications class
Browse files Browse the repository at this point in the history
  • Loading branch information
adamski committed Apr 20, 2021
1 parent c480615 commit d8930ba
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions modules/juce_gui_extra/native/juce_android_PushNotifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<jobject> (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<jobject> (env->CallObjectMethod (intent, AndroidIntent.getData));
auto intentDataString = juceString ((jstring) env->CallObjectMethod (intentDataUri, AndroidUri.toString));

JUCEApplication::getInstance()->anotherInstanceStarted (intentDataString);
}

PushNotifications& owner;
};

Expand Down Expand Up @@ -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))
{
Expand Down

0 comments on commit d8930ba

Please sign in to comment.