Taskbar icon indicating copy to clipboard operation
Taskbar copied to clipboard

Intent: launch app

Open gsus24 opened this issue 4 years ago • 6 comments

Hello tried out the freeform mode for the first time. Is there a possibility to launch apps through intent with specific size, position and show,hide ? Would be easy to implement, if not present yet, hope to see this in future. Thanks

gsus24 avatar Feb 10 '21 22:02 gsus24

The Intent with ActivityOptions can set starting location and size with parameter called LaunchBounds. The Taskbar uses it for freeform window bounds. But it doesn't provide mechanism to show/hide window.

utzcoz avatar Feb 12 '21 04:02 utzcoz

Ok. Found this on class U

launchApp(context, () -> {
                Intent intent = new Intent(context, DummyActivity.class);
                intent.putExtra("accessibility", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

                try {
                    context.startActivity(intent, getActivityOptionsBundle(context, ApplicationType.APP_PORTRAIT, null));
                } catch (IllegalArgumentException | SecurityException ignored) {}
            });

But didnt find a receiver to start it from outside, i mean from other app. Did i understood it righ, this is not possible without a receiver? I will give a try to implement this. Hope you know which extras should be passed.

gsus24 avatar Feb 12 '21 14:02 gsus24

Ok. Found this on class U

launchApp(context, () -> {
                Intent intent = new Intent(context, DummyActivity.class);
                intent.putExtra("accessibility", true);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_ANIMATION);

                try {
                    context.startActivity(intent, getActivityOptionsBundle(context, ApplicationType.APP_PORTRAIT, null));
                } catch (IllegalArgumentException | SecurityException ignored) {}
            });

But didnt find a receiver to start it from outside, i mean from other app. Did i understood it righ, this is not possible without a receiver? I will give a try to implement this. Hope you know which extras should be passed.

It is not processed by other app, it is processed by frameworks, specifically TaskLaunchParameters.

utzcoz avatar Feb 12 '21 14:02 utzcoz

Before closing this thread. I would know your opinion about implementing such feature and hopefully you have some suggestions on doing this.

What would be great is to pass packagename, window size and position to open/close an app like on the normal way android doing it.

gsus24 avatar Feb 16 '21 19:02 gsus24

Before closing this thread. I would know your opinion about implementing such feature and hopefully you have some suggestions on doing this.

What would be great is to pass packagename, window size and position to open/close an app like on the normal way android doing it.

If you want to open one app with specific package name, and specific position, you can check the above launchApp method you found in Taskbar. If you want to close one app with specific package name, maybe you should check ActivityManager methods, and make sure you have the granted permission to close one task or finish one process based on your found methods, if they exist.

utzcoz avatar Feb 17 '21 14:02 utzcoz

If somebody interest in I implement a BroadcastReceiver and pass packagename and componentname from outside

public static class MyBroadcastReceiver extends BroadcastReceiver
    {
        @Override
        public void onReceive(Context context, Intent intent)
        {
            String pkg= intent.getStringExtra("pkg");
            String comp= intent.getStringExtra("comp");
            final AppEntry entry = new AppEntry(pkg, comp, null, null, false);
            long userId = entry.getUserId(context);
            entry.setUserId(userId);
            String windowSize = "standard";

            // #todo: pass window dimension and position
            U.launchApp(context, entry, windowSize, () -> {
                Intent launch = new Intent(Intent.ACTION_VIEW);
                try {
                    context.startActivity(intent, U.getActivityOptionsBundle(context, ApplicationType.APP_PORTRAIT, null));
                } catch (ActivityNotFoundException | IllegalArgumentException ignored) {}
            });

        }
    }

and register it in Manifest

<receiver android:name=".activity.MainActivity$MyBroadcastReceiver">
            <intent-filter>
                <action android:name="com.my.app" />
            </intent-filter>
        </receiver>

from outside send broadcast

Intent launchIntent = new Intent();
launchIntent.setAction("com.myapp");
launchIntent.putExtra("pkg", pkg);
launchIntent.putExtra("comp", comp);
launchIntent.setPackage("com.farmerbb.taskbar.debug");
launchIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
sendBroadcast(launchIntent);

This works fine, if checkbox for saving windowsize is enabled and one time setting the prefered windowsize and position. But only mobile Samsung S9. On Shield TV it is only working unless reboot.

U.launchApp(context, entry, windowSize, () -> This windowSize is standard or the other definitions Any tips to pass window dimensions and position ???

gsus24 avatar Feb 17 '21 18:02 gsus24