Create shortcut?

Post your questions and help other users.

Moderator: Martin

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Create shortcut?

Post by Bluscre » 31 Aug 2018 02:43

I got stuck here:

Image
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Create shortcut?

Post by Desmanto » 02 Sep 2018 17:02

You are trying to add a shortcut to the home screen?

Why don't you try action send broadcast? But I understand much about converting it from java, maybe something like this?

Action : com.android.launcher.action.INSTALL_SHORTCUT
Extras : putString("Intent.EXTRA_SHORTCUT_INTENT", "");

I don't know where to put the package name of the intended shortcut.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Create shortcut?

Post by Bluscre » 03 Sep 2018 20:15

Tried it without success
Image

@martin please explain
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Create shortcut?

Post by Martin » 06 Sep 2018 18:45

Hi,

Could you please explain in more detail what you want to achieve? I think you can only build a shortcut that will start an activity. The process is more or less like this:
1. create an Intent that will launch the desired activity
2. create an intent with action com.android.launcher.action.INSTALL_SHORTCUT and add the first intent as extra with key android.intent.extra.shortcut.INTENT (that's the actual value of Intent.EXTRA_SHORTCUT_INTENT).
3. send the second intent as a broadcast and hope that the system/launcher supports this way to create shortcuts (it won't work on Android 8+).

I would recommend to use action Send Broadcast and put the entire script into the field Extras but honestly I didn't have the time to check if this actually works (should in theory).

Regards,
Martin

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Create shortcut?

Post by Bluscre » 07 Sep 2018 14:48

Welp, i'm sorry but you lost me on the third sentence :(

To explain; i have a few that i toggle (unfreeze/freeze) via an automagic shortcut
Whenever i unfreeze the apps i want shortcuts to be created for each of them
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Create shortcut?

Post by Martin » 09 Sep 2018 13:46

There was a function missing in Automagic to create shortcuts. I've added the missing piece in the 1.36 EAP build.
The following flow shows how it can be achieved:
Flow: Create Shortcut Example

Please note that you have to modify the flow to pick the desired icon and edit the action Send Broadcast to launch the app you'd like.
The flow will likely not work on Android 8+ since shortcuts have to be created in another way starting with Android 8.

Regards,
Martin

User avatar
Desmanto
Posts: 2709
Joined: 21 Jul 2017 17:50

Re: Create shortcut?

Post by Desmanto » 09 Sep 2018 16:30

Thanks. I actually spend some of the time in last several days to find this, but to use java and parcelable, I am lost already. Tested this on LP 5.1, the shortcut is created directly to nova home screen. Haven't tried this in Oreo. AFAIK, oreo requires the shortcut created to be confirmed again by the launcher.

@Bluscre : Since there is a way already above, I stop finding the solution. I will present the alternate solution for your need. Your main problem is the shortcut disappear after you freeze the app. And you want it to appear back again after unfreeze.

1. Proxy your shortcut
Since the app disappear/appear, but Automagic stay at there, you can proxy the shortcut thru automagic trigger shortcut. Simply create new flow with shortcut, let's say "Chrome". Then the flow only contain single action Launch App - Chrome. Add this shortcut to your home screen. When you freeze Chrome, this shortcut stay. The downside is, if you tap this shortcut when the app is frozen, it will result in error. You can supress it by link Launch App to exception with blank action.

2. Use launcher with Automagic support
AFAIK, lightning launcher support automation. But this limit your choice to use lightning launcher only. I don't use it, so can't say much.

3. Use Widget to replace the shortcut
It is similar to the solution 1, but this one using widget instead. The plus point is, you can use the script to change the widget to become transparant after freezing the app. So you won't see any icon in the launcher. It still consume the space in the launcher, but I am sure you have reserved that place for that specific app, so it is fine. You can also supress the tap, by using condition to check if Chrome exists or not. So when you mis tap the transparent widget, it won't do anything when Chrome is Frozen.
Index of Automagic useful thread List of my other useful posts (and others')
Xiaomi Redmi Note 5 (whyred), AOSP Extended v6.7 build 20200310 Official, Android Pie 9.0, Rooted.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Create shortcut?

Post by Bluscre » 17 Sep 2018 15:47

@martin thanks for your example, it works just fine :) what do you mean by missing piece? I just installed eap 1.36 but still no "Create shortcut" action.

@Desmanto that idea is kinda good but not really since i want the apps that will be shortcutted to be dynamic. @martins method is perfekt even tho i wish there was a action for it.
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Bluscre
Posts: 145
Joined: 31 Aug 2017 13:58
Location: Germany
Contact:

Re: Create shortcut?

Post by Bluscre » 17 Sep 2018 16:13

Also when trying on more than one app i get

Code: Select all

17.09.2018 18:11:13.854 [Toggle Flirt Apps] Action 'Send Broadcast: com.android.launcher.action.INSTALL_SHORTCUT ' Could not start activity using intent: Intent { act=com.android.launcher.action.INSTALL_SHORTCUT flg=0x10000000 (has extras) }
java.lang.RuntimeException: Failure from system
	at android.app.ContextImpl.sendBroadcast(ContextImpl.java:777)
	at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:396)
	at ch.gridvision.ppam.androidautomagic.model.a.dv.a(SourceFile:165)
	at ch.gridvision.ppam.androidautomagic.model.a.d$1.b(SourceFile:415)
	at ch.gridvision.ppam.androidautomagiclib.util.ci$1$1.run(SourceFile:52)
	at android.os.Handler.handleCallback(Handler.java:815)
	at android.os.Handler.dispatchMessage(Handler.java:104)
	at android.os.Looper.loop(Looper.java:207)
	at android.app.ActivityThread.main(ActivityThread.java:5765)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.os.TransactionTooLargeException: data parcel size 1049480 bytes
	at android.os.BinderProxy.transactNative(Native Method)
	at android.os.BinderProxy.transact(Binder.java:511)
	at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3217)
	at android.app.ContextImpl.sendBroadcast(ContextImpl.java:772)
	... 11 more

17.09.2018 18:11:13.862 [Toggle Flirt Apps] End executing action 'Send Broadcast: com.android.launcher.action.INSTALL_SHORTCUT ' and exception Failure from system
17.09.2018 18:11:14.610 [Toggle Flirt Apps] Action 'Execute Root Command: pm enable {package_name} in ' stdout=Package im.howlr.app new state: enabled

17.09.2018 18:11:14.610 [Toggle Flirt Apps] Action 'Execute Root Command: pm enable {package_name} in ' stderr=
17.09.2018 18:11:14.610 [Toggle Flirt Apps] Action 'Execute Root Command: pm enable {package_name} in ' exit_code=0
17.09.2018 18:11:14.611 [Toggle Flirt Apps] End executing action 'Execute Root Command: pm enable {package_name} in '
17.09.2018 18:11:14.620 [Toggle Flirt Apps] Flow ends execution due to errors
17.09.2018 18:11:14.621 [Toggle Flirt Apps] Error:
java.lang.RuntimeException: Failure from system
	at android.app.ContextImpl.sendBroadcast(ContextImpl.java:777)
	at android.content.ContextWrapper.sendBroadcast(ContextWrapper.java:396)
	at ch.gridvision.ppam.androidautomagic.model.a.dv.a(SourceFile:165)
	at ch.gridvision.ppam.androidautomagic.model.a.d$1.b(SourceFile:415)
	at ch.gridvision.ppam.androidautomagiclib.util.ci$1$1.run(SourceFile:52)
	at android.os.Handler.handleCallback(Handler.java:815)
	at android.os.Handler.dispatchMessage(Handler.java:104)
	at android.os.Looper.loop(Looper.java:207)
	at android.app.ActivityThread.main(ActivityThread.java:5765)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
Caused by: android.os.TransactionTooLargeException: data parcel size 1049480 bytes
	at android.os.BinderProxy.transactNative(Native Method)
	at android.os.BinderProxy.transact(Binder.java:511)
	at android.app.ActivityManagerProxy.broadcastIntent(ActivityManagerNative.java:3217)
	at android.app.ContextImpl.sendBroadcast(ContextImpl.java:772)
	... 11 more

17.09.2018 18:11:14.625 [Toggle Flirt Apps] Flow ended.
Unofficial AutoMagic Telegram Group: https://t.me/automagicforandroid
Check out my other flows here: https://github.com/Bluscream/AutoMagicFlows or here.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Create shortcut?

Post by Martin » 21 Sep 2018 09:52

The missing piece was a missing function to add a parcelable to the broadcast intent (putParcelable). The function is used to add the icon to the intent.

The exception is likely caused by adding an icon that's too large. You can try to scale the image down a bit before adding it to the intent.

Post Reply