创建桌面快捷方式

来源:互联网 发布:网络捕鱼游戏下载 编辑:程序博客网 时间:2024/06/10 03:32

1:权限

    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS"/>    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>

2:代码

/**   *   创建桌面快捷方式     */  public void createShut() {    // 创建添加快捷方式的Intent     Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  String title = getResources().getString(R.string.app_name);  // 加载快捷方式的图标     Parcelable icon = Intent.ShortcutIconResource.fromContext(Appstart.this, R.drawable.ic_launcher);   // 创建点击快捷方式后操作Intent,该处当点击创建的快捷方式后,再次启动该程序  Intent myIntent = new Intent(Appstart.this,Appstart.class);  // 设置快捷方式的标题     addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);  // 设置快捷方式的图标  addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);  // 设置快捷方式对应的Intent  addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myIntent);  // 发送广播添加快捷方式  sendBroadcast(addIntent);    }


0 0
原创粉丝点击