Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a shortcut for any app on desktop?

I think I've tried all the solutions I found on the internet, but no one worked - no force close, but nothing appears on desktop.

Now, I have this:

private void createShortcutOnDesktop(Application app) {

    Intent shortcutIntent = new Intent();
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, app.getIntentShortcut());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, app.getName());
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.home_button));
    shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    this.sendBroadcast(shortcutIntent);
    finish();

}

The app.getIntentShortcut():

public Intent getIntentShortcut() { 

    Intent i = new Intent();
    i.setClassName(packageName, name);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    return i;
}

And in the AndroidManifest.xml file:

<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

What am I missing? Thanks.

like image 927
xuso Avatar asked Jun 27 '11 13:06

xuso


People also ask

How do I put an app shortcut on my desktop?

Select Start , scroll to the app you want to pin, then press and hold (or right-click) the app. Select More > Pin to taskbar. If the app is already open on the desktop, press and hold (or right click) the app's taskbar icon, and then select Pin to taskbar.

How do I create a shortcut on Windows 10?

Desktop shortcuts in Windows 10Click Start (the Windows orb) and go to All Apps. Find the program you want to create a desktop shortcut to and right-click on it. Click Send to and you'll see various destinations, one being Desktop (create Shortcut). Clicking on this will then make a shortcut on the Desktop.


1 Answers

Solved. Just change at manifest:

this:

<permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

to this:

<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

Just an 'uses' ¬¬

like image 125
xuso Avatar answered Oct 19 '22 13:10

xuso