Page 1 of 2

Create shortcut?

Posted: 31 Aug 2018 02:43
by Bluscre
I got stuck here:

Image

Re: Create shortcut?

Posted: 02 Sep 2018 17:02
by Desmanto
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.

Re: Create shortcut?

Posted: 03 Sep 2018 20:15
by Bluscre
Tried it without success
Image

@martin please explain

Re: Create shortcut?

Posted: 06 Sep 2018 18:45
by Martin
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

Re: Create shortcut?

Posted: 07 Sep 2018 14:48
by Bluscre
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

Re: Create shortcut?

Posted: 09 Sep 2018 13:46
by Martin
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

Re: Create shortcut?

Posted: 09 Sep 2018 16:30
by Desmanto
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.

Re: Create shortcut?

Posted: 17 Sep 2018 15:47
by Bluscre
@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.

Re: Create shortcut?

Posted: 17 Sep 2018 16:13
by Bluscre
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.

Re: Create shortcut?

Posted: 21 Sep 2018 09:52
by Martin
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.