现在的位置: 首页 > 综合 > 正文

android 创建shortcut

2013年09月19日 ⁄ 综合 ⁄ 共 1781字 ⁄ 字号 评论关闭

1.manifest中添加permis:

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

 

2.创建shortcut的intent:

                                       Intent shortcut = new Intent(
                                                "com.android.launcher.action.INSTALL_SHORTCUT");
                                        shortcut.putExtra("duplicate", true);
                                        shortcut.putExtra(
                                                Intent.EXTRA_SHORTCUT_NAME,
                                                detail.getListing().getName());
                                        ShortcutIconResource iconRes = Intent.ShortcutIconResource
                                                .fromContext(
                                                        MobileProfileActivity.this,
                                                        R.drawable.mobile_android_tip_directions);
                                        shortcut.putExtra(
                                                        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                        iconRes);
                                        ComponentName comp = new ComponentName(
                                                MobileProfileActivity.this.getPackageName(),
                                                AndroidSearch.class.getCanonicalName());

                                        Intent i = new Intent(
                                                Intent.ACTION_MAIN);
                                        i.putExtra(AppConstants.KEY_DIRECTIONS_LISTING_ID,
                                                        detail.getListingId());
                                        i.setAction(AppConstants.KEY_ACTION_PIN_DIRECTIONS);
                                        i.setComponent(comp);
                                        i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                                        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT,i);

                                        sendBroadcast(shortcut);

抱歉!评论已关闭.