如何以编程方式创建的Andr​​oid另一个应用程序的快捷方式? [英] How to programmatically create a shortcut of another app in Android?

查看:125
本文介绍了如何以编程方式创建的Andr​​oid另一个应用程序的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设,我有一些Android应用程序,它可以帮助用户安装一些其他应用程序。有什么办法创造主屏幕上的应用程序这一个捷径?我还可以指定这些快捷键的位置?

Suppose, I have some Android app which helps users to install some other apps. Is there any way to create a shortcut of this apps on home screen? Can I also specify the position of these shortcuts?

推荐答案

试试这个:

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("com.whatsapp"));
    sendBroadcast(shortcutintent);
}

这篇关于如何以编程方式创建的Andr​​oid另一个应用程序的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆