From e96a10bb0f6de6ff740bc131e23689c0c9ee75f1 Mon Sep 17 00:00:00 2001 From: "chengjian.scj" Date: Wed, 12 Feb 2025 10:30:05 +0800 Subject: [PATCH] Change the activity launch type to home --- .../genymobile/scrcpy/video/NewDisplayCapture.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java index 6098238d..87d54e4f 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/NewDisplayCapture.java @@ -15,6 +15,7 @@ import com.genymobile.scrcpy.util.AffineMatrix; import com.genymobile.scrcpy.util.Ln; import com.genymobile.scrcpy.wrappers.ServiceManager; +import android.annotation.SuppressLint; import android.app.ActivityOptions; import android.content.Intent; import android.content.pm.PackageManager; @@ -25,7 +26,9 @@ import android.os.Build; import android.view.Surface; import java.io.IOException; +import java.lang.reflect.Method; +@SuppressLint({"PrivateApi", "SoonBlockedPrivateApi", "BlockedPrivateApi"}) public class NewDisplayCapture extends SurfaceCapture { // Internal fields copied from android.hardware.display.DisplayManager @@ -281,11 +284,15 @@ public class NewDisplayCapture extends SurfaceCapture { if (secondaryHomeResolveInfo.activityInfo.packageName.equals(homeResolveInfo.activityInfo.packageName)) { Intent launcherIntent = new Intent(); launcherIntent.setClassName(secondaryHomeResolveInfo.activityInfo.packageName, secondaryHomeResolveInfo.activityInfo.name); - launcherIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK - | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); - + ActivityOptions options = ActivityOptions.makeBasic(); options.setLaunchDisplayId(virtualDisplayId); + try { + Method method = ActivityOptions.class.getDeclaredMethod("setLaunchActivityType", int.class); + method.invoke(options, /* ACTIVITY_TYPE_HOME */ 2); + } catch(Exception e) { + Ln.e("Could not invoke method", e); + } ServiceManager.getActivityManager().startActivity(launcherIntent, options.toBundle()); }