diff --git a/modules/juce_core/native/juce_android_JNIHelpers.h b/modules/juce_core/native/juce_android_JNIHelpers.h index ceb8dc3948..2cb3dccd4c 100644 --- a/modules/juce_core/native/juce_android_JNIHelpers.h +++ b/modules/juce_core/native/juce_android_JNIHelpers.h @@ -318,6 +318,8 @@ extern AndroidSystem android; METHOD (unbindService, "unbindService", "(Landroid/content/ServiceConnection;)V") \ METHOD (startIntentSenderForResult, "startIntentSenderForResult", "(Landroid/content/IntentSender;ILandroid/content/Intent;III)V") \ METHOD (getPackageName, "getPackageName", "()Ljava/lang/String;") \ + METHOD (moveTaskToBack, "moveTaskToBack", "(Z)Z") \ + METHOD (startActivity, "startActivity", "(Landroid/content/Intent;)V") \ DECLARE_JNI_CLASS (JuceAppActivity, JUCE_ANDROID_ACTIVITY_CLASSPATH); #undef JNI_CLASS_MEMBERS diff --git a/modules/juce_core/native/juce_mac_Threads.mm b/modules/juce_core/native/juce_mac_Threads.mm index 8ac6c0ed52..25b16f7eb7 100644 --- a/modules/juce_core/native/juce_mac_Threads.mm +++ b/modules/juce_core/native/juce_mac_Threads.mm @@ -55,10 +55,14 @@ JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() JUCE_API void JUCE_CALLTYPE Process::hide() { - #if JUCE_MAC if (! SystemStats::isRunningInAppExtensionSandbox()) + { + #if JUCE_MAC [NSApp hide: nil]; - #endif + #elif JUCE_IOS + [[UIApplication sharedApplication] performSelector: @selector(suspend)]; + #endif + } } JUCE_API void JUCE_CALLTYPE Process::raisePrivilege() diff --git a/modules/juce_core/threads/juce_Process.h b/modules/juce_core/threads/juce_Process.h index 1804b89452..99d4ba0716 100644 --- a/modules/juce_core/threads/juce_Process.h +++ b/modules/juce_core/threads/juce_Process.h @@ -71,7 +71,7 @@ public: */ static void JUCE_CALLTYPE makeForegroundProcess(); - /** Hides the application (on an OS that supports this, e.g. OSX) */ + /** Hides the application (on an OS that supports this, e.g. OSX, iOS, Android) */ static void JUCE_CALLTYPE hide(); //============================================================================== diff --git a/modules/juce_gui_basics/native/juce_android_Windowing.cpp b/modules/juce_gui_basics/native/juce_android_Windowing.cpp index 54fa3ea608..6abf191c6a 100644 --- a/modules/juce_gui_basics/native/juce_android_Windowing.cpp +++ b/modules/juce_gui_basics/native/juce_android_Windowing.cpp @@ -29,6 +29,14 @@ extern juce::JUCEApplicationBase* juce_CreateApplication(); // (from START_JUCE_ namespace juce { +#define JNI_CLASS_MEMBERS(METHOD, STATICMETHOD, FIELD, STATICFIELD) \ + METHOD (constructor, "", "()V") \ + METHOD (setAction, "setAction", "(Ljava/lang/String;)Landroid/content/Intent;") \ + METHOD (addCategory, "addCategory", "(Ljava/lang/String;)Landroid/content/Intent;") \ + +DECLARE_JNI_CLASS (Intent, "android/content/Intent"); +#undef JNI_CLASS_MEMBERS + //============================================================================== #if JUCE_IN_APP_PURCHASES && JUCE_MODULE_AVAILABLE_juce_product_unlocking extern void juce_inAppPurchaseCompleted (void*); @@ -793,11 +801,24 @@ ModifierKeys ModifierKeys::getCurrentModifiersRealtime() noexcept return AndroidComponentPeer::currentModifiers; } +JUCE_API void JUCE_CALLTYPE Process::hide() +{ + if (android.activity.callBooleanMethod (JuceAppActivity.moveTaskToBack, true) == 0) + { + auto* env = getEnv(); + + GlobalRef intent (env->NewObject (Intent, Intent.constructor)); + env->CallObjectMethod (intent, Intent.setAction, javaString ("android.intent.action.MAIN") .get()); + env->CallObjectMethod (intent, Intent.addCategory, javaString ("android.intent.category.HOME").get()); + + android.activity.callVoidMethod (JuceAppActivity.startActivity, intent.get()); + } +} + //============================================================================== // TODO JUCE_API bool JUCE_CALLTYPE Process::isForegroundProcess() { return true; } JUCE_API void JUCE_CALLTYPE Process::makeForegroundProcess() {} -JUCE_API void JUCE_CALLTYPE Process::hide() {} //============================================================================== void JUCE_CALLTYPE NativeMessageBox::showMessageBoxAsync (AlertWindow::AlertIconType /*iconType*/,