Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding an app shortcut to android homescreen in an Ionic + Cordova app

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?

like image 527
Yossale Avatar asked Mar 18 '23 06:03

Yossale


1 Answers

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

like image 163
Manish Karena Avatar answered Apr 24 '23 18:04

Manish Karena