title: How to add app's shortcut to the home screen
body: <p>I know it's not documented and won't work on every device, but I see more and more apps placing their shortcuts on the home screen after they got installed.
  Found bunch of code chunks how to do it but for me they don't fit together.
  This is what I got for now.</p>
  
  <ol>
  <li><p>Need a permission in the manifest.</p>
  
  <pre><code>&lt;uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" /&gt;
  </code></pre></li>
  <li><p>Create an Intent of activity that should be called. Ex (from cgeek):</p>
  
  <pre><code>Intent shortcutIntent = new Intent();
  shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
  shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
  </code></pre></li>
  <li><p>Create shortcut itself</p>
  
  <pre><code>Intent addIntent = new Intent();
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
  addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
  addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
  context.sendBroadcast(addIntent);
  </code></pre></li>
  </ol>
  
  <p>My questions is:
  Where this code should go to make shortcut added after .apk installed? I tried this code in the launcher activity, it creates broken(another story) shortcut every time app starts.</p>