I'm writing an ionic app for android (in coffeescript and angular), and I want to add a shortcut to the app on the homescreen. Google didn't help, and this cordova/phonegap plugin won't work either.
Any idea on how to do it?
Since ICS, you can do like this:
public void createShortCut(){
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcutname));
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext, R.drawable.icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext, EnterActivity.class));
sendBroadcast(shortcutintent);
}
Also add permission in AndroidManifest.xml like this:
<uses-permission
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
<uses-permission
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
Please also refer to the source code of launcher at: this link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With