在Ionic Cordova应用程序中添加应用程序快捷方式到android主屏幕

我正在为 android编写一个离子应用程序(使用coffeescript和angular),我想在主屏幕上添加应用程序的快捷方式.谷歌没有帮助,this cordova/phonegap插件也无法正常工作.

有什么想法怎么做?

解决方法

从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" />

另请参阅启动器的源代码:this link

相关文章

公司前端界面用的是vue,我要嵌入到Android中生成App第一步:...
Q:我用cordova开发项目,想在app内跳转外部链接,安装了cord...
我正在使用https://github.com/arnesson/cordova-plugin-fir...
一、Cordova的基础点在混合式应用中,我们通过现有的Cordova...
cordova自定义插件注意:存放自定义cordova插件目录不能有空...
一、问题VueAPP中有一个文件下载功能,用了各种方法来实现下...