【问题标题】:Adding an app shortcut to android homescreen in an Ionic + Cordova app在 Ionic + Cordova 应用程序中向 android 主屏幕添加应用程序快捷方式
【发布时间】:2015-01-28 12:19:45
【问题描述】:

我正在为 android 编写一个 ionic 应用程序(在 coffeescript 和 angular 中),我想在主屏幕上添加一个应用程序的快捷方式。谷歌没有帮助,this cordova/phonegap 插件也不起作用。

你知道怎么做吗?

【问题讨论】:

  • 您是使用 Ionic + Cordova 构建应用还是使用 Ionic CSS 框架构建 Web 应用?
  • 那么你必须有一个.apk 文件(由 bu​​ild -> ionic build android 生成)。只需将其安装在您的手机/平板电脑上,您的应用程序就会出现其徽标...
  • 原生 android 行为将应用程序放在应用程序抽屉中,而不是在主屏幕上。应用程序可以在打开时将自身添加到主屏幕。这就是我想要的。

标签: android cordova ionic-framework cordova-plugins


【解决方案1】:

从 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

【讨论】:

  • 谢谢,但您的回答对原生 android 应用程序有效。我在问一个离子应用程序......
  • 我想他是在告诉你制作一个可以本地调用它的插件。
猜你喜欢
  • 1970-01-01
  • 2011-10-22
  • 2014-02-27
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-29
相关资源
最近更新 更多