首页 > 移动平台 > 详细

android创建桌面快捷方式(启动目标非项目的启动页)

时间:2015-05-11 12:41:50      阅读:329      评论:0      收藏:0      [点我收藏+]

1.布局文件中,目标Activity加入以下filter

    <intent-filter>  
                <action android:name="android.intent.action.CREATE_SHORTCUT" />  
                <category android:name="android.intent.category.DEFAULT" />  
            </intent-filter>

 

2.通过发送广播的方式调用

      Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");  
                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.seckill));//设置快捷图标的名字
                    shortcut.putExtra("duplicate", false);//设置是否重复创建  
                    Intent intent = new Intent();  
                    intent.addCategory(Intent.CATEGORY_LAUNCHER);
                    intent.setClass(getActivity(), ProductListActivity.class);//设置第一个页面
                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);  
                    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.wx_friend_non);//设置快捷图标的资源
                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);  
                    getActivity().sendBroadcast(shortcut);

android创建桌面快捷方式(启动目标非项目的启动页)

原文:http://www.cnblogs.com/bravestarrhu/p/4494157.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!