网友通过本文主要向大家介绍了android studio,android studio官网,android studio下载,android studio教程,android studio配置等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
Android,androidstudio
/**
*
* 返回添加到桌面快捷方式的Intent:
*
* 1.给Intent指定action="com.android.launcher.INSTALL_SHORTCUT"
*
* 2.给定义为Intent.EXTRA_SHORTCUT_INENT的Intent设置与安装时一致的action(必须要有)
*
* 3.添加权限:com.android.launcher.permission.INSTALL_SHORTCUT
*/
public Intent getShortcutToDesktopIntent(Context context) {
Intent intent = new Intent();
intent.setClass(context, context.getClass());
/* 以下两句是为了在卸载应用的时候同时删除桌面快捷方式 */
intent.setAction("android.intent.action.MAIN");
intent.addCategory("android.intent.category.LAUNCHER");
Intent shortcut = new Intent(
"com.android.launcher.action.INSTALL_SHORTCUT");
// 不允许重建
shortcut.putExtra("duplicate", false);
// 设置名字
// shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,context.getString(R.string.app_name));
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "11111");
// 设置图标
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,
R.drawable.youtube));
// 设置意图和快捷方式关联程序
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
return shortcut;
}
权限
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
调用
public void click1(View v) {
Intent intent = this.getShortcutToDesktopIntent(MainActivity.this);
sendBroadcast(intent);
}
您可能想查找下面的文章:
- Android Studio混淆打包错误
- Android Studio 错误解决办法
- android studio开发控件布局
- 1.0 Android基础入门教程
- 2.2.3 TableLayout(表格布局)
- 2.3.2 EditText(输入框)详解
- android入门,看这一本书就够了,android入门,
- Android studio 下的SDK Manager只显示已安装包的情况,androidsdk
- Android 知识Tips,android知识tips
- Android Studio: Error:Cannot locate factory for objects of type DefaultGradleConnector, as ConnectorServiceRegistry,locateregistry

