如何创建上安装Android手机主屏幕上的应用程序快捷方式 [英] how to create app shortcut on home screen on Android phones on installation
本文介绍了如何创建上安装Android手机主屏幕上的应用程序快捷方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经创建了一个Android应用程序,它工作正常
但现在我想补充一点,在安装应用程序应创建主屏幕上的快捷方式功能
I have created an android application , which works fine but now i want to add a feature that on installation the application should create a shortcut on home screen
请建议
我不想完整code工作
简单的步骤,就足够了。
please suggest i don't want the complete code work simple steps would be enough
推荐答案
首先声明,您的应用程序正在使用在AndroidManifest.xml中INSTALL_SHORTCUT许可。
First declare that your application is using the INSTALL_SHORTCUT permission in the AndroidManifest.xml.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld");
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
这篇关于如何创建上安装Android手机主屏幕上的应用程序快捷方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文