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);

更多相关文章

  1. android 备忘录之简单实现
  2. Android给图片添加认证水印
  3. Android(安卓)Wear创建通知的几种方式
  4. android 输入对话框
  5. Android中九种dialog对话框代码
  6. Android菜单实例
  7. android 图片缩放
  8. Android(安卓)中的 requestWindowFeature
  9. 在/external/tinyalsa/pcm.c 添加android log

随机推荐

  1. 关于android工程中R.java不自动生成的问
  2. android activity开发文档翻译 - 1 - 基
  3. Android中的Context
  4. Android推送通知指南
  5. Ubuntu 10.04下Android开发环境的搭建
  6. Handler Looper源码解析(Android消息传递
  7. android 导入 3d 场景
  8. Android之NDK开发
  9. Android中数据存储——ContentProvider存
  10. android升级adt和sdk之后无法识别SDK Loc