Can we make shortcuts?

hackhack

Active Member
Licensed User
Longtime User
On a PC if I have created a file, say a word document - I can right click on it and select "create shortcut" and then place that shortcut somewhere else, say on the desktop. If I later click on the shortcut of the document it launches the program set up to open word documents and loads the document.

I'd like to make that kind of shortcuts on the Android.

Now on the Android, if i long press on my Desire I get a popup menu with the items Widget/App/Shortcut/Folder - there are somewhat similar menus on different devices, but they probably all have "App" and "Shortcut" as two of the menu choices. The "App" choice adds what I would call a shortcut to an app (only) on the Android 'desktop' and "shortcut" is something else - shortcuts seem to be somewhat related to a widget, but isn't a widget (confusing much Google?)

NOW - if you download the Astro file manager from the market, and go to the above mentioned menu item called "Shortcut" (in Honeycomb it is called "more") Astro starts up and lets you find any file on the Android device and create a shortcut. You could select a pdf or sound or picture etc. You then get a shortcut on the desktop. If its a shortcut to a picture and you click it and the default picture viewer will launch and show the picture.

NOW if you uninstall the Astro filemanager the shortcuts remain on the desktop AND THEY STILL WORK

Meaning Android supports in some way.

So my question is can we in Basic 4 Android program this ability?
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Okay, I understand now.
So our Activity will return an intent to the launcher (which contains another intent which is the actual shortcut function)
This is slightly different than what I was thinking but it looks right.

I think hackhack was trying to create a shortcut from within his app.
Not sure if that is possible (or even right), looking at this method.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Everytime someone comes up with 'b4a doesnt support this yet' you come up with a whole bunch of tutorials and examples!!!

Hey, I didn't say it couldn't do it - I was asking IF and HOW :)

I think hackhack was trying to create a shortcut from within his app.
Not sure if that is possible (or even right), looking at this method.

??? But surely the code posts from erel does exactly that! (And as I have written several times in the this thread, many other apps do that including "Astro")
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Hey, I didn't say it couldn't do it - I was asking IF and HOW :)
I know, my friend, I wasnt talking about you. Just a general thing I keep seeing on the forums :)

??? But surely the code posts from erel does exactly that! (And as I have written several times in the this thread, many other apps do that including "Astro")
Go ahead and try it and let us know if it does what you expected :)
I will try it when I get home
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
And for a moment I thought that you will write: "thank you for writing this tutorial to answer (or at least try to answer) my question".
I said it first! (although it wasnt my question)...but with your speed i have to say it again. Thanks Erel...I am still wondering how you are so fast!

thank you for writing your tutorial :)
you are welcome :) ...just kidding, it wasnt me :p

anyways, hackhack can you tell me how Astro shortcut works? As far as I can see, you have to LongPress=>Shortcuts and add something from there. You cannot add shortcuts when you are inside the Astro application, can you?

The one thing which is annoying to me if you move the shortcut creation routine out to the main app and run it then it doesn't work - it has to be created on call initiated from Android shortcut menu (the Honeycomb "more") - can that be avoided?

Your intent doesnt know where to go. We know it is directed towards a launcher but you can have 10 launchers on your phone, which one does your intent go to?
I havent seen anyone do this yet, but maybe it is possible. (How to create home screen short cut? - Android Developers | Google Groups)
What I dont know if we can broadcast an intent or not? I thought StartActivity will broadcast an intent. (but that attempt went down the drain!)
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
you are welcome :)

Thank you for confusing me further with your tutorials ;-)

...just kidding, it wasnt me :p

Just kidding as well ;)

anyways, hackhack can you tell me how Astro shortcut works? As far as I can see, you have to LongPress=>Shortcuts and add something from there. You cannot add shortcuts when you are inside the Astro application, can you?

Well, I set out to research two goals, and erels code in the other thread solves one of them.

You are inside Astro, but its the way you get there. You get there the same was as with Erels code: You long press and from the menu that pops up you press the icon.

This then launches Astro/yourapp and in that context you make a shortcut. This works now with Erels code.

Now in the case of Astro I could navigate to a picture: flower.jpg then Astro will make a shortcut on the desktop to the file "flower.jpg" - if I click the shortcut a picture viewer will start up and show the picture BUT its the system default picture viewer not Astro - if I uninstall Astro the shortcut remains on the desktop and still works.

That bit I don't know.

You are right there is some additional magic, because apparently you can't just create a shortcut from the app if its started "normally".

Now some apps can do this, most notably the Android market app just generates shortcuts - but perhaps this is a Google privileged function (or there is some other magic going on)



Your intent doesnt know where to go. We know it is directed towards a launcher but you can have 10 launchers on your phone, which one does your intent go to?

I think i see what you mean. You may well be right, I just don't like the design. I think the OS should generate these shortcut files and they clearly contain intents (witness the astro shortcut left behind) so why should it be the task of the launcher to make them? (I'm not saying it isn't, just that i find it puzzling)


I havent seen anyone do this yet, but maybe it is possible. (How to create home screen short cut? - Android Developers | Google Groups)
What I dont know if we can broadcast an intent or not? I thought StartActivity will broadcast an intent. (but that attempt went down the drain!)

Next step is to find out how Android knows what apps to call when different (mime?) types are encountered - ie "oh, this is a picture, then I'm going to call SuperDuperPictureShower" and how it does that - then see if it can be tied to this :)

Ooh, gotta eat something first though ;)
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
Will this also accept intents?

I managed to make my app support creating shortcuts on the home screen to do specific things. This was adapted from Erel's sample:

B4X:
Dim shortcutIntent As Intent
shortcutIntent.Initialize("", "")
shortcutIntent.SetComponent(Common.ShortcutPackage & "/.shortcutexec")
shortcutIntent.PutExtra("from_shortcut", True)
shortcutIntent.PutExtra("sc_type", SCType)
shortcutIntent.PutExtra("sc_value", SCValue)
shortcutIntent.PutExtra("sc_destination", SCDestination)
shortcutIntent.PutExtra("sc_toast", SCToast)
shortcutIntent.PutExtra("sc_notification", SCNotification)
shortcutIntent.PutExtra("sc_extra1", "")
shortcutIntent.PutExtra("sc_extra2", "")
Dim in As Intent
in.Initialize("", "")
in.PutExtra("android.intent.extra.shortcut.INTENT", shortcutIntent)
in.PutExtra("android.intent.extra.shortcut.NAME", txtName.Text)
in.PutExtra("android.intent.extra.shortcut.ICON", LoadBitmap(File.DirAssets, imageFN))

My question is, does this now allow my app to accept intents from other apps (if I were to share the required options)? If possible, I'd like others to be able to send intents to my app just like in a shortcut, but I don't know where to begin.
 
Upvote 0

Kevin

Well-Known Member
Licensed User
Longtime User
I'm trying to work around some issues and was wondering if I can have a shortcut start a service instead of an activity? Anyone know? Yes, I could just try it but I've got some errands to run today first so I didn't want to waste time trying something that won't work. :eek:
 
Upvote 0
Top