Create Shortcut intent
Moderator: Martin
Create Shortcut intent
Hi. Could someone pls tell me how I can use the broadcast intent action to create a new Shortcut in the default Android launcher? Thx
Re: Create Shortcut intent
Hi,
Here's a link to a possible way using regular Java:
https://gist.github.com/zeuxisoo/1008973
You probably have to do it using the Java functions of action Script since adding the extra EXTRA_SHORTCUT_ICON_RESOURCE is not supported in Automagic.
Regards,
Martin
Here's a link to a possible way using regular Java:
https://gist.github.com/zeuxisoo/1008973
You probably have to do it using the Java functions of action Script since adding the extra EXTRA_SHORTCUT_ICON_RESOURCE is not supported in Automagic.
Regards,
Martin
Re: Create Shortcut intent
Hi Martin, thx. It's getting too complicated. Could U guide me through the process pls ?
So
intent=callJavaConstructor("android.content.Intent", "Intent(java.lang.String)","com.android.launcher.action.INSTALL_SHORTCUT"); //should it not be android.intent.action.CREATE_SHORTCUT ?
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', 'MyShortcut');
//this is where it gets shady; the component name should be the app to which i'm sending the broadcast to or AUTOMAGIC ?
compName=callJavaConstructor("android.content.ComponentName", "ComponentName(java.lang.String, java.lang.String)", 'com.google.android.apps.nexuslauncher', 'com.android.launcher3.InstallShortcutReceiver');
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', '_bogdyro');
NewIntent = callJavaConstructor("android.content.Intent", "Intent(java.lang.String)","ACTION_MAIN");
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', NewIntent);
compName=callJavaConstructor("android.content.ComponentName", "ComponentName(java.lang.String, java.lang.String)", 'com.google.android.apps.nexuslauncher', 'com.android.launcher3.InstallShortcutReceiver');
//next java method call should have two parameters, string and Intent; I can't find this method
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
//how do I pass the path to an .ico or .png file to create the shortcut icon ?
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_INTENT','/storage/emulated/0/Download/ios7/TTF.ico');
//send broadcast
callJavaMethod(getContext(), "android.content.Context", "sendBroadcast(android.content.Intent)", intent);
So
intent=callJavaConstructor("android.content.Intent", "Intent(java.lang.String)","com.android.launcher.action.INSTALL_SHORTCUT"); //should it not be android.intent.action.CREATE_SHORTCUT ?
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', 'MyShortcut');
//this is where it gets shady; the component name should be the app to which i'm sending the broadcast to or AUTOMAGIC ?
compName=callJavaConstructor("android.content.ComponentName", "ComponentName(java.lang.String, java.lang.String)", 'com.google.android.apps.nexuslauncher', 'com.android.launcher3.InstallShortcutReceiver');
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', '_bogdyro');
NewIntent = callJavaConstructor("android.content.Intent", "Intent(java.lang.String)","ACTION_MAIN");
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_NAME', NewIntent);
compName=callJavaConstructor("android.content.ComponentName", "ComponentName(java.lang.String, java.lang.String)", 'com.google.android.apps.nexuslauncher', 'com.android.launcher3.InstallShortcutReceiver');
//next java method call should have two parameters, string and Intent; I can't find this method
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
//how do I pass the path to an .ico or .png file to create the shortcut icon ?
callJavaMethod(intent, "android.content.Intent", "putExtra(java.lang.String, java.lang.String)", 'EXTRA_SHORTCUT_INTENT','/storage/emulated/0/Download/ios7/TTF.ico');
//send broadcast
callJavaMethod(getContext(), "android.content.Context", "sendBroadcast(android.content.Intent)", intent);
Re: Create Shortcut intent
Hi,
Please check the following flow:
http://automagic4android.com/flow.php?i ... 4344a05a41
The bitmap is loaded using the action Init Variable Image File. Please note that the image should not be too large, otherwise it can not be added to the intent, respectively the intent can not be sent. I've used an app icon since the size should be OK to use it as a shortcut icon.
The variable intentToStart should be set to an activity intent that directly launches an activity and to which both Automagic and the Launcher have the permission to start. The launcher verifies that the intent is valid and will silently discard the shortcut when the intent is not valid for some reason.
The extra names EXTRA_SHORTCUT_NAME etc. have to be replaced by the actual String values (e.g. "android.intent.extra.shortcut.NAME") (lines 5, 6, 7 in the Script).
Regards,
Martin
Please check the following flow:
http://automagic4android.com/flow.php?i ... 4344a05a41
The bitmap is loaded using the action Init Variable Image File. Please note that the image should not be too large, otherwise it can not be added to the intent, respectively the intent can not be sent. I've used an app icon since the size should be OK to use it as a shortcut icon.
The variable intentToStart should be set to an activity intent that directly launches an activity and to which both Automagic and the Launcher have the permission to start. The launcher verifies that the intent is valid and will silently discard the shortcut when the intent is not valid for some reason.
The extra names EXTRA_SHORTCUT_NAME etc. have to be replaced by the actual String values (e.g. "android.intent.extra.shortcut.NAME") (lines 5, 6, 7 in the Script).
Regards,
Martin
Re: Create Shortcut intent
Sorry to bug you. Tried it but it doesn't work. Isn't there a way to debug this intent? There is an app that 8ntercepts intents but it doesn't get triggered.
Anything else I could try? Thanks
Anything else I could try? Thanks
Re: Create Shortcut intent
Hmmm. No error shown in the log of Automagic?
Maybe the image could not be loaded. Try to use http://automagic4android.com/logo.png as the image in action Init Variable Image File.
Android is also very picky about the intent to start. Try to change the intent to launch the system settings, which should work on most devices.
To do this, replace the first two lines of the script with:
Also check the android system log. My device logs an error when the intent to start is not valid that reads: E/InstallShortcutReceiver: Ignoring malicious intent #Intent;action=...;end
Regards,
Martin
Maybe the image could not be loaded. Try to use http://automagic4android.com/logo.png as the image in action Init Variable Image File.
Android is also very picky about the intent to start. Try to change the intent to launch the system settings, which should work on most devices.
To do this, replace the first two lines of the script with:
Code: Select all
intentToStart=callJavaConstructor("android.content.Intent", "Intent(java.lang.String)", "android.settings.SETTINGS");
Regards,
Martin
Re: Create Shortcut intent
Hi Martin. It just started working out of the blue. Only needed to change the activity name. Anywyay,no error in automagic log or catlog when it wasn't working. Strange.
Now I would like to make a shortcut to an AM trigger. Is that possible via script.
Also, as a general request, do you think it's doable to edit every java action in a script by opening that helper dialog?
Thanks
Now I would like to make a shortcut to an AM trigger. Is that possible via script.
Also, as a general request, do you think it's doable to edit every java action in a script by opening that helper dialog?
Thanks
Re: Create Shortcut intent
Android does not notify apps about the problem when the intent is not valid. Android just ignores the intent and writes one error log to the system log of Android, not the log of Automagic. Glad it's working now 
You could use the trigger Send/Share Intent Received to execute a flow. You have to change the first few lines of the script to create a SEND-intent like this:
Regards,
Martin

You could use the trigger Send/Share Intent Received to execute a flow. You have to change the first few lines of the script to create a SEND-intent like this:
Code: Select all
intentToStart=callJavaConstructor("android.content.Intent", "Intent(java.lang.String)", "android.intent.action.SEND");
callJavaMethod(intentToStart, "android.content.Intent", "setClassName(java.lang.String, java.lang.String)", "ch.gridvision.ppam.androidautomagic", "ch.gridvision.ppam.androidautomagic.SendIntentReceiverActivity");
Martin
Re: Create Shortcut intent
Well, I was talking about logcat. Isn't that the mother of all android logs ? Couldn't find any error there either. Anyway, thx for the second snippet of code.