在Ionic + Cordova应用中将应用程序快捷方式添加到安卓主屏幕

4
我正在使用coffeescript和angular为Android编写ionic应用程序,并希望在主屏幕上添加一个应用程序快捷方式。谷歌没有提供帮助,而this cordova/phonegap插件也无法正常工作。你有什么想法吗?

你是在使用Ionic + Cordova构建应用程序,还是在使用Ionic CSS框架构建Web应用程序? - Riron
然后你必须有一个 .apk 文件(由构建生成 -> ionic build android)。只需将其安装到您的手机/平板电脑上,您的应用程序就会出现并显示其标志... - Riron
原生的Android行为是将应用程序放在应用抽屉中,而不是主屏幕上。当打开应用程序时,应用程序可以将自己添加到主屏幕上。这就是我想要的。 - Yossale
1个回答

7
自ICS开始,您可以这样做:
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);
}

还需要在 AndroidManifest.xml 文件中添加权限,如下所示:
<uses-permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

请参考以下启动器的源代码:此链接

1
谢谢,但是你的回答适用于原生安卓应用。我在询问一个Ionic应用程序... - Yossale
我认为他是告诉你要制作一个调用本地内容的插件。 - Bon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接