我正在为
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