I'm struggling with making social-buttons work within an android app on android 12. The buttons are intended to simply open a URL (e.g. https://twitter.com/netflix). By my understanding the view intent should be automatically handed over to the proper app, which is able to handle it. So in case of a twitter url, with the twitter app installed, it should open the twitter app. In case no specific app is installed, it should open the URL using the default browser.
What I experience is that URLs like https://google.com are properly opened in the browser. But when trying to open https://twitter.com/netflix, there is just nothing happening. The URL is not opening in the browser, nor in the twitter app. But when uninstalling twitter, the URL opens in the browser as expected. So I guess I'm missing something to make non-browser apps handle the URL as expected. Strange thing: when opening https://twitter.com, the twitter app opens instead of the browser.
This is what I have in the queries element of my manifest file:
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent>
</queries>
Also: This is an unreal engine based project, so the code used for opening/launching the URL using an ACTION_VIEW intent is part of the engine source code. Ideally I want to find a solution to make this work without having to modify this engine code. Here the code snipped that is responsible for opening the URL:
public void AndroidThunkJava_LaunchURL(String URL)
{
Log.debug("[JAVA} AndroidThunkJava_LaunchURL: URL = " + URL);
if (!URL.contains("://"))
{
// add http:// if there isn't a scheme before a colon
if (URL.indexOf(":") < 1)
{
URL = "http://" + URL;
Log.debug("[JAVA} AndroidThunkJava_LaunchURL: corrected URL = " + URL);
}
}
try
{
Intent BrowserIntent = new Intent(Intent.ACTION_VIEW, android.net.Uri.parse(URL));
// open browser on its own task
BrowserIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
BrowserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
// make sure there is a web browser to handle the URL before trying to start activity (or may crash!)
if (BrowserIntent.resolveActivity(getPackageManager()) != null)
{
Log.debug("[JAVA} AndroidThunkJava_LaunchURL: Starting activity");
startActivity(BrowserIntent);
}
else
{
Log.debug("[JAVA} AndroidThunkJava_LaunchURL: Could not find an application to receive the URL intent");
}
}
catch (Exception e)
{
Log.debug("[JAVA} AndroidThunkJava_LaunchURL: Failed with exception " + e.getMessage());
}
}
The best solution seems to upgrade the Unreal Engine Project to 4.27 which includes the following commit: https://github.com/EpicGames/UnrealEngine/commit/e49afc395b171e1d0c39e2d79b16ca2be8ea982c
This adds BrowserIntent.addCategory(Intent.CATEGORY_BROWSABLE); to the function that is responsible for starting the intent and thereby makes it work for devices with target SDK 30.