Android在DeskTop添加快捷方式

来源:互联网 发布:汇编语言与c语言区别 编辑:程序博客网 时间:2024/06/15 20:58

       通过查看android源码可以读取android系统如何创建快捷图标,仿照源码读取方式可以编写出创建快捷方式的方法


      添加权限:     <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>


                //设置路径 频道 Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");//名字 :Stringintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "测试图标");//图标 : 图片--如果没有设置图片ShortcutIconResource res =ShortcutIconResource.fromContext(this,R.drawable.icon_app);intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, res);//当我们点击的时候,启动应用(Activity):意图Intent intent2 = new Intent(this,MainActivity.class);intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent2);

                           设置只允许创建一个快捷图标:

               

              intent.putExtra("duplicate", true);

                            备注:这种方式适合创建app图标是drawable文件夹下的图片,如果是本地或者网络图片如果这种方式创建不成功可以参考源码修改图片的extra数据

0 0
原创粉丝点击