Any ideas how to do it?
< /p>
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);
)
You can also add permissions in AndroidManifest.xml, as shown below:
android:name="com.android.launcher. permission.INSTALL_SHORTCUT" />
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
Please also refer to the source code of the launcher: this link
I am writing an ionic application for android (using coffeescript and angular), I I want to add a shortcut to the application on the home screen. Google didn’t help, and this cordova/phonegap plugin doesn’t work.
Any ideas how to do it?
Starting from ICS, you can do 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);
)
You can also add permissions in AndroidManifest.xml , As follows:
android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
Please also refer to the source code of the launcher: this link
< p>