From 7b0341123ba4dae5cb1303f4094162cb670f23e7 Mon Sep 17 00:00:00 2001 From: Julian Winkler Date: Tue, 25 Mar 2025 19:15:36 +0100 Subject: [PATCH] startActivityForResult(): add initial support for android.intent.action.INSTALL_PACKAGE For now this just calls 'android-translation-layer --install' on the given APK file. Which would then show the dynamic launcher portal. --- src/api-impl/android/app/Activity.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/api-impl/android/app/Activity.java b/src/api-impl/android/app/Activity.java index ff14361c..19d41aa0 100644 --- a/src/api-impl/android/app/Activity.java +++ b/src/api-impl/android/app/Activity.java @@ -27,6 +27,7 @@ import android.view.Window; import android.view.WindowManager; import android.view.WindowManagerImpl; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -337,6 +338,19 @@ public class Activity extends ContextThemeWrapper implements Window.Callback, La } } else if (FILE_CHOOSER_ACTIONS.contains(intent.getAction())) { nativeFileChooser(FILE_CHOOSER_ACTIONS.indexOf(intent.getAction()), intent.getType(), intent.getStringExtra("android.intent.extra.TITLE"), requestCode); + } else if ("android.intent.action.INSTALL_PACKAGE".equals(intent.getAction())) { + try { + Process p = new ProcessBuilder("/usr/bin/env", "android-translation-layer", "--install", intent.getData().getPath()).start(); + int exitValue = p.waitFor(); + if (exitValue == 0) { + onActivityResult(requestCode, -1 /*RESULT_OK*/, new Intent()); + } else { + onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent()); + } + } catch (IOException | InterruptedException e) { + e.printStackTrace(); + onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent()); + } } else { Slog.i(TAG, "startActivityForResult: intent was not handled. Calling onActivityResult(RESULT_CANCELED)."); onActivityResult(requestCode, 0 /*RESULT_CANCELED*/, new Intent());