Android: Process::OpenDocument crashes

When trying to navigate to a website by calling URL::launchInDefaultBrowser on Android (which subsequently calls Process::OpenDocument), this call crashes the app.

Now, I’m not sure if something like app signing is at play… so I’m wondering if anybody else is seeing the same thing on their end.

I am seeing this using JUCE 8. Has anyone figured out what the issue is?

No idea. The support for Android has been meagre and anemic at best.

I believe getCurrentActivity is returning nullptr.

Here’s a stack trace from Google Play Console:

JNI DETECTED ERROR IN APPLICATION: obj == null

_JNIEnv::CallVoidMethod(_jobject*, _jmethodID*, …)
sdk/ndk/28.2.13676358/toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include/jni.h:631:9

juce::Process::openDocument(juce::String const&, juce::String const&)
modules/juce_core/native/juce_Files_android.cpp:903:10

juce::URL::launchInDefaultBrowser() const
modules/juce_core/network/juce_URL.cpp:1024:12

juce::Button::sendClickMessage(juce::ModifierKeys const&)

Here’s my version of juce’s Process::openDocument:

895 JUCE_API bool JUCE_CALLTYPE Process::openDocument (const String& fileName, const String&)
896 {
897 URL targetURL (fileName);
898 auto* env = getEnv();
899
900 const LocalRef action (javaString (“android.intent.action.VIEW”));
901 LocalRef intent (env->NewObject (AndroidIntent, AndroidIntent.constructWithUri, action.get(), urlToUri (targetURL).get()));
902
903 env->CallVoidMethod (getCurrentActivity(), AndroidContext.startActivity, intent.get());
904 return true;
905 }

Seems this is related to another issue with the current activity:

Could be related to permissions, could be an API thing, it’s hard to say. You’ll probably get more information in the logs via Logcat.