Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating shortcuts in Android via ADB

Tags:

android

adb

It is possible to create a shortcut from ADB on the launcher of my android? I have a .bat file to install my applications from my PC (through double click), but after this I need always to search on the huge (not so user friendly) applications list of the launcher. If it was possible to add this feature to my .bat file would be great. I already try to search on the web without any luck :S.

Thanks in advance

like image 467
Jóni Avatar asked Jan 19 '13 02:01

Jóni


People also ask

How do I create a custom shortcut on Android?

Find the app you want to create a shortcut for and long-press on its icon. Tap Add to home. On some Android devices, you will need to long-press the icon and drag the app to the home screen. The app's icon should then appear in the top-right corner of your Home screen on your Android tablet or smartphone.

What can I do with ADB commands?

Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device.


1 Answers

There's a couple of ways to handle this. If your main need is to be able to start your application quickly each time you do a re-edit, then an adb shell am intent -n com.example.app/.App is the easiest solution.

If you want to just make a shortcut (and you don't care where) use com.android.launcher.action.INSTALL_SHORTCUT as everyone says. You'll need an app or bin to do that as the am broadcast won't take nested intents.

If you are working with a specific launcher (like ADW Launcher) you can hack the database of shortcuts. This will allow you to specify the coordinates of the shortcut ([2, 3] in this case)

adb shell sqlite3 /data/data/org.adw.launcher/databases/launcher.db "DELETE FROM favorites WHERE _id=1; INSERT INTO favorites VALUES(1,'MyApp','#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.example.app/.App;end',-100,0,2,3,1,1,0,-1,NULL,0,NULL,NULL,NULL,NULL,NULL);"

You'll need to tell the launcher to refresh from the database. Usually the only way is to kill the launcher. Later versions of am (the ActivityManager shell command) have options for restarting a package, earlier versions don't. In that case you'd need to write a small app:

ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
am.restartPackage("org.adw.launcher");
like image 95
Renate Avatar answered Oct 11 '22 13:10

Renate