11

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.

paulina_glab
  • 2,467
  • 2
  • 16
  • 25
xuso
  • 695
  • 1
  • 8
  • 19

1 Answers1

15

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' ¬¬

xuso
  • 695
  • 1
  • 8
  • 19
  • Your code seems to produce a desktop shortcut on Execution of the program ! Is there a way by which i can create a desktop icon on installation of the app before running it.? – Ajith M A May 07 '13 at 09:55
  • No you cannot because the java code has to be inside the main activity which is ran when you launch the app – Jad Joubran Jun 12 '13 at 16:12