/**
   * This function creates a shortcut and returns it to the caller. There are actually two intents
   * that you will send back.
   *
   * <p>The first intent serves as a container for the shortcut and is returned to the launcher by
   * setResult(). This intent must contain three fields:
   *
   * <ul>
   *   <li>{@link android.content.Intent#EXTRA_SHORTCUT_INTENT} The shortcut intent.
   *   <li>{@link android.content.Intent#EXTRA_SHORTCUT_NAME} The text that will be displayed with
   *       the shortcut.
   *   <li>{@link android.content.Intent#EXTRA_SHORTCUT_ICON} The shortcut's icon, if provided as a
   *       bitmap, <i>or</i> {@link android.content.Intent#EXTRA_SHORTCUT_ICON_RESOURCE} if provided
   *       as a drawable resource.
   * </ul>
   *
   * If you use a simple drawable resource, note that you must wrapper it using {@link
   * android.content.Intent.ShortcutIconResource}, as shown below. This is required so that the
   * launcher can access resources that are stored in your application's .apk file. If you return a
   * bitmap, such as a thumbnail, you can simply put the bitmap into the extras bundle using {@link
   * android.content.Intent#EXTRA_SHORTCUT_ICON}.
   *
   * <p>The shortcut intent can be any intent that you wish the launcher to send, when the user
   * clicks on the shortcut. Typically this will be {@link android.content.Intent#ACTION_VIEW} with
   * an appropriate Uri for your content, but any Intent will work here as long as it triggers the
   * desired action within your Activity.
   */
  private void setupShortcut(Account account, long mailboxId, String shortcutName) {
    Activity myActivity = this;
    // First, set up the shortcut intent.
    final Intent shortcutIntent;
    if (TEST_CREATE_OLD_STYLE_SHORTCUT) {
      shortcutIntent = MessageList.createFroyoIntent(myActivity, account);
      Log.d(Logging.LOG_TAG, "Created old style intent: " + shortcutIntent);
    } else {
      // TODO if we add meta-mailboxes/accounts to the database, remove this special case
      if (account.mId == Account.ACCOUNT_ID_COMBINED_VIEW) {
        shortcutIntent =
            Welcome.createOpenMessageIntent(myActivity, account.mId, mailboxId, Message.NO_MESSAGE);
      } else {
        String uuid = account.mCompatibilityUuid;
        shortcutIntent = Welcome.createAccountShortcutIntent(myActivity, uuid, mailboxId);
      }
    }

    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
    Parcelable iconResource =
        Intent.ShortcutIconResource.fromContext(myActivity, R.mipmap.ic_launcher_email);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    myActivity.setResult(Activity.RESULT_OK, intent);
  }
  protected void setupShortcut(Venue venue) {
    // First, set up the shortcut intent. For this example, we simply create
    // an intent that
    // will bring us directly back to this activity. A more typical
    // implementation would use a
    // data Uri in order to display a more specific result, or a custom
    // action in order to
    // launch a specific operation.

    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, VenueActivity.class.getName());
    shortcutIntent.putExtra(Foursquared.EXTRA_VENUE_ID, venue.getId());

    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, venue.getName());
    Parcelable iconResource =
        Intent.ShortcutIconResource.fromContext(this, R.drawable.venue_shortcut_icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher

    setResult(RESULT_OK, intent);
  }
Esempio n. 3
0
  public void save(View v) {
    Intent shortcut = new Intent(Intent.ACTION_SEND);
    TextView addr = (TextView) findViewById(R.id.addr);
    TextView subject = (TextView) findViewById(R.id.subject);
    TextView body = (TextView) findViewById(R.id.body);
    TextView name = (TextView) findViewById(R.id.name);

    if (!TextUtils.isEmpty(addr.getText())) {
      shortcut.putExtra(Intent.EXTRA_EMAIL, new String[] {addr.getText().toString()});
    }

    if (!TextUtils.isEmpty(subject.getText())) {
      shortcut.putExtra(Intent.EXTRA_SUBJECT, subject.getText().toString());
    }

    if (!TextUtils.isEmpty(body.getText())) {
      shortcut.putExtra(Intent.EXTRA_TEXT, body.getText().toString());
    }

    shortcut.setType("text/plain");

    Intent result = new Intent();

    result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcut);
    result.putExtra(Intent.EXTRA_SHORTCUT_NAME, name.getText().toString());
    result.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

    setResult(RESULT_OK, result);
    finish();
  }
Esempio n. 4
0
  /**
   * Creates a home screen shortcut.
   *
   * @param fileHolder The {@link File} to create the shortcut to.
   */
  public static void createShortcut(FileHolder fileHolder, Context context) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, fileHolder.getName());
    try {
      shortcutIntent.putExtra(
          Intent.EXTRA_SHORTCUT_ICON,
          bitmapFrom(context.getResources().getDisplayMetrics(), fileHolder.getBestIcon()));
    } catch (Exception ex) {
      Logger.log(ex);
      Parcelable icon =
          Intent.ShortcutIconResource.fromContext(
              context.getApplicationContext(), R.drawable.ic_launcher);
      shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    } finally {
      Intent onClickIntent = new Intent(Intent.ACTION_VIEW);
      if (fileHolder.getFile().isDirectory())
        onClickIntent.setData(Uri.fromFile(fileHolder.getFile()));
      else
        onClickIntent.setDataAndType(Uri.fromFile(fileHolder.getFile()), fileHolder.getMimeType());
      onClickIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);

      shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, onClickIntent);
      context.sendBroadcast(shortcutIntent);
    }
  }
Esempio n. 5
0
  // setShortcut(): Sets up the intent for Google Maps and creates the shortcuts on the user's
  // homescreen.
  private void setShortcut(int mode) {

    // Sets the reference to the address input.
    EditText address_1 = (EditText) findViewById(R.id.address_input_1);
    String location = new String();

    // Retrieves the address from the user's input.
    try {
      location = address_1.getText().toString();
      location = location.replace(" ", "+");
    }

    // NullPointerException handler.
    catch (NullPointerException e) {

      // A Toast message appears, notifying the user about the error.
      toastyPopUp("ERROR: NULLPOINTEREXCEPTION ENCOUNTERED WHILE RETRIEVING ADDRESS INPUT.");
    }

    // Launches Google Map in navigation mode and begins navigation immediately.
    Intent shortcutIntent =
        new Intent(
            android.content.Intent.ACTION_VIEW, Uri.parse("google.navigation:q=" + location));
    shortcutIntent.setAction(Intent.ACTION_VIEW);

    // Adds the address in the customized intent for Google Maps.
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, address_1.getText().toString());

    int iconResource = R.drawable.home_icon; // Used for setting the shortcut icon resource.

    // Sets the icon based on the selected mode.
    switch (mode) {

        // HOME:
      case 0:
        iconResource = R.drawable.home_icon;
        break;

        // WORK:
      case 1:
        iconResource = R.drawable.work_icon;
        break;

        // PLACE:
      case 2:
        iconResource = R.drawable.place_icon;
        break;
    }

    // Sets the icon resource for the shortcut.
    addIntent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(getApplicationContext(), iconResource));

    // Installs the shortcut on the homescreen.
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);
  }
  public void setShortCut(String camera) {
    Toast.makeText(
            getActivity().getApplicationContext(), "Shortcut on Home Screen", Toast.LENGTH_LONG)
        .show();

    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW);
    shortcutIntent.setClassName(getActivity().getPackageName(), ".HomeActivity");

    shortcutIntent.putExtra(HomeActivity.URL, mURL);
    shortcutIntent.putExtra(HomeActivity.HEADER, title);
    shortcutIntent.putExtra(HomeActivity.MYDELAY, delay);
    shortcutIntent.putExtra(HomeActivity.WHICHCAM, state);

    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, camera);
    intent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(
            getActivity().getApplicationContext(), R.drawable.icon));
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getActivity().getApplicationContext().sendBroadcast(intent);
    getActivity().setResult(getActivity().RESULT_OK, intent);
  }
  @Override
  public void onIconItemClick(int style, int position) {
    L.i("onIconItemClick: " + style + "/" + position);
    int[] tmp = null;
    switch (style) {
      case IconGridViewAdapter.STYLE_SMARTISAN_1:
        tmp = IconGridViewAdapter.smartisan_res_1;
        break;
      case IconGridViewAdapter.STYLE_SMARTISAN_2:
        tmp = IconGridViewAdapter.smartisan_res_2;
        break;
      case IconGridViewAdapter.STYLE_SMARTISAN_3:
        tmp = IconGridViewAdapter.smartisan_res_3;
        break;
      case IconGridViewAdapter.STYLE_SMARTISAN_4:
        tmp = IconGridViewAdapter.smartisan_res_4;
        break;
      case IconGridViewAdapter.STYLE_IPHONE:
        tmp = IconGridViewAdapter.iphone_res;
        break;
      case IconGridViewAdapter.STYLE_COLD_1:
        tmp = IconGridViewAdapter.cold_res_1;
        break;
      default:
        break;
    }

    String input_name = input.getText().toString();
    if (tmp != null)
      createShortcut(
          TextUtils.isEmpty(input_name) ? " " : input_name,
          packageName,
          activityName,
          Intent.ShortcutIconResource.fromContext(PickIconActivity.this, tmp[position]));
  }
Esempio n. 8
0
 /**
  * 创建桌面快捷方式
  *
  * @param resId 应用图标 <uses-permission
  *     android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
  */
 public void createShortcut(int resId) {
   Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
   shortcut.putExtra("duplicate", false);
   ComponentName comp =
       new ComponentName(context.getPackageName(), "." + ((Activity) context).getLocalClassName());
   shortcut.putExtra(
       Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
   ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(context, resId);
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
   context.sendBroadcast(shortcut);
 }
Esempio n. 9
0
  private void setupShortcut() {
    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, this.getClass().getName());

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcut_addtask_name));
    Parcelable iconResource =
        Intent.ShortcutIconResource.fromContext(this, R.drawable.todotxt_touch_icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    setResult(RESULT_OK, intent);
  }
 /**
  * @param context
  * @brief methods for creating app shortcut icon on home screen
  */
 public static void createShortcut(Context context) {
   Intent shortcutIntent = new Intent(context, context.getClass());
   shortcutIntent.setAction(Intent.ACTION_MAIN);
   Intent addIntent = new Intent();
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
   addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
   addIntent.putExtra(
       Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
       Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher));
   addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
   context.sendBroadcast(addIntent);
   savePreference(context, "SHORTCUT_CREATED", 1);
 }
Esempio n. 11
0
  @Override
  public void onStart(Intent intent, int startId) {

    Intent installShortCut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    installShortCut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "WifiÉèÖÃ");
    Parcelable icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.wifi);
    installShortCut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    Intent wifiSettingsIntent = new Intent("android.settings.WIFI_SETTINGS");
    installShortCut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, wifiSettingsIntent);

    sendBroadcast(installShortCut);

    super.onStart(intent, startId);
  }
  /**
   * Setup a search short cut.
   *
   * @param startPoint the start point
   * @param endPoint the end point
   */
  protected void onCreateShortCut(String startPoint, String endPoint) {
    Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint);
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, this, RoutesActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, startPoint + " " + endPoint);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    setResult(RESULT_OK, intent);
    finish();
  }
Esempio n. 13
0
  private void setupShortcut(Account account) {
    final Intent shortcutIntent = FolderList.actionHandleAccountIntent(this, account, null, true);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    String description = account.getDescription();
    if (description == null || description.length() == 0) {
      description = account.getEmail();
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    setResult(RESULT_OK, intent);
    finish();
  }
Esempio n. 14
0
 /** 创建快捷方式 */
 public static void addShortCut(Context context) {
   Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 设置属性
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
   ShortcutIconResource resource =
       Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher);
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, resource);
   // 是否允许重复创建
   shortcut.putExtra("duplicate", false);
   Intent intent = new Intent(Intent.ACTION_MAIN); // 标识Activity为一个程序的开始
   intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
   intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
   intent.addCategory(Intent.CATEGORY_LAUNCHER);
   intent.setClass(context, SplashActivity.class);
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   context.sendBroadcast(shortcut);
 }
Esempio n. 15
0
  /** 创建快捷方式 */
  public void createDeskShortCut() {
    // 创建快捷方式的Intent
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 不允许重复创建
    shortcutIntent.putExtra("duplicate", false);
    // 需要显示的名称
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));

    // 快捷图片
    Parcelable icon =
        Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher);

    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    Intent intent = new Intent(getApplicationContext(), WelcomePageActivity.class);
    // 下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    // 点击快捷图片,运行的程序主入口
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    // 发送广播。OK
    sendBroadcast(shortcutIntent);

    // 在配置文件中声明已经创建了快捷方式
    getSharedPreferences("shortcut", Context.MODE_PRIVATE)
        .edit()
        .putBoolean("iscreated", true)
        .commit();

    // 2.3.3系统创建快捷方式不提示
    /*
     * if (android.os.Build.VERSION.SDK.equals("10")) { Toast.makeText(
     * this, "已创建" + this.getResources().getString(R.string.app_name) +
     * "快捷方式。", Toast.LENGTH_LONG).show(); }
     */

    String handSetInfo =
        "手机型号:"
            + android.os.Build.MODEL
            + ",SDK版本:"
            + android.os.Build.VERSION.SDK
            + ",系统版本:"
            + android.os.Build.VERSION.RELEASE;
    Log.e("HANDINFO", handSetInfo);
  }
Esempio n. 16
0
 /**
  * 建立快捷方式
  *
  * @param context
  */
 public static void createShortCut(Context context, String name, int callFrom) {
   Intent returnIntent = new Intent();
   // 设置创建快捷方式的过滤器action
   returnIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重复创建
   returnIntent.putExtra("duplicate", false);
   // 设置生成的快捷方式的名字
   returnIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
   // 设置生成的快捷方式的图标
   returnIntent.putExtra(
       Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
       Intent.ShortcutIconResource.fromContext(context, R.drawable.we));
   Intent intent = new Intent(context, MainActivity.class);
   intent.putExtra(ExtraName.CALL_FROM, callFrom);
   returnIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   // 发送广播生成快捷方式
   context.sendBroadcast(returnIntent);
 }
Esempio n. 17
0
 public void creatShortCut(Activity activity, String shortCutName, int resourceId) {
   Intent intent = new Intent(activity, activity.getClass());
   /** 卸载应用并删除图标 */
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重复
   shortcutintent.putExtra("duplicate", false);
   // 设置标题
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
   // 设置图标
   Parcelable icon =
       Intent.ShortcutIconResource.fromContext(activity.getApplicationContext(), resourceId);
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
   // 点击快捷方式,运行入口
   shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   activity.sendBroadcast(shortcutintent);
 }
Esempio n. 18
0
 /**
  * 创建快捷方式.
  *
  * @param shuortcutName
  * @param launcherResId
  */
 public static void createShorts(String shuortcutName, int launcherResId) {
   // 创建快捷方式的Intent
   Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重复创建
   shortcutIntent.putExtra("duplicate", false);
   // 需要现实的名称
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shuortcutName);
   // 快捷图片
   Parcelable icon = Intent.ShortcutIconResource.fromContext(application.get(), launcherResId);
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
   Intent intent = new Intent(application.get(), application.get().getClass());
   // 下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   // 点击快捷图片,运行的程序主入口
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   // 发送广播。OK
   application.get().sendBroadcast(shortcutIntent);
 }
Esempio n. 19
0
    private void returnShortcut(String name, String command) {
        Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
        shortcutIntent.setClassName(this, CommCareHomeActivity.class.getName());
        shortcutIntent.putExtra(EXTRA_KEY_SHORTCUT, command);
        
        //Home here makes the intent new every time you call it
        shortcutIntent.addCategory(Intent.CATEGORY_HOME);

        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
        Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this,  R.mipmap.ic_launcher);
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

        // Now, return the result to the launcher

        setResult(RESULT_OK, intent);
        finish();
        return;
    }
Esempio n. 20
0
  public static void addShortcut(Context context, Intent intent, int name, int icon) {

    String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
    // 快捷方式要启动的包

    // 设置快捷方式的参数
    Intent shortcutIntent = new Intent(ACTION_INSTALL_SHORTCUT);
    // 设置名称
    shortcutIntent.putExtra(
        Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(name)); // 设置启动 Intent
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    // 设置图标
    shortcutIntent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(context, icon));
    // 只创建一次快捷方式
    shortcutIntent.putExtra("duplicate", false);
    // 创建
    context.sendBroadcast(shortcutIntent);
  }
Esempio n. 21
0
 public static void create(Context context, Class<?> cls) {
   Intent intent = new Intent();
   intent.setClass(context, cls.getClass());
   /* 以下两句是为了在卸载应用的时候同时删除桌面快捷方式 */
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重建
   shortcut.putExtra("duplicate", false);
   // 设置名字
   shortcut.putExtra(
       Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(R.string.app_name));
   // 设置图标
   shortcut.putExtra(
       Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
       Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher));
   // 设置意图和快捷方式关联程序
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   context.sendBroadcast(shortcut);
 }
Esempio n. 22
0
 /** 创建桌面快捷图标 */
 private void installShortCut() {
   boolean shortcut = sp.getBoolean("shortcut", false);
   if (shortcut) { // 如果桌面已存在快捷图标,则不创建
     return;
   }
   Editor editor = sp.edit();
   Intent intent = new Intent();
   intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
   intent.putExtra(
       Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
       Intent.ShortcutIconResource.fromContext(this, R.drawable.logo)); // 快捷图标
   intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "恋恋日记本"); // 名称
   Intent clickIntent = new Intent();
   clickIntent.setAction("android.intent.action.MAIN");
   clickIntent.addCategory("android.intent.category.LAUNCHER");
   clickIntent.setClassName(getPackageName(), "com.carrie.lldiary.SplashActivity");
   intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, clickIntent);
   sendBroadcast(intent);
   editor.putBoolean("shortcut", true);
   editor.commit();
 }
Esempio n. 23
0
  public void addShortCut() {
    // 创建快捷方式的Intent
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 不允许重复创建
    shortcut.putExtra("duplicate", false);
    // 需要显示的名称
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    Intent shortcutIntent = new Intent();
    // 以下两行fix Bug 248112——创建快捷方式,两者不关联
    shortcutIntent.setAction("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.setClass(this, MainActivity.class);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    // 快捷方式的图标
    ShortcutIconResource iconRes =
        Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    sendBroadcast(shortcut);
  }
Esempio n. 24
0
  public void addShortCut() {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    // 设置属性
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
    ShortcutIconResource iconRes =
        Intent.ShortcutIconResource.fromContext(
            edittext.this, R.drawable.btn_style_alert_dialog_button_pressed);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, iconRes);

    // 是否允许重复创建
    shortcut.putExtra("duplicate", false);
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    intent.addFlags(Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setClass(edittext.this, MainMicroDiary.class);
    // 设置启动程序
    System.out.println("createIcon");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    edittext.this.sendBroadcast(shortcut);
  }
Esempio n. 25
0
  // credits Financisto
  // src/ru/orangesoftware/financisto/activity/PreferencesActivity.java
  private void addShortcut(String activity, int nameId, int iconId, Bundle extra) {
    Intent shortcutIntent = createShortcutIntent(activity);
    if (extra != null) {
      shortcutIntent.putExtras(extra);
    }
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(nameId));
    intent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, iconId));
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

    if (Utils.isIntentReceiverAvailable(this, intent)) {
      sendBroadcast(intent);
      Toast.makeText(getBaseContext(), getString(R.string.pref_shortcut_added), Toast.LENGTH_LONG)
          .show();
    } else {
      Toast.makeText(
              getBaseContext(), getString(R.string.pref_shortcut_not_added), Toast.LENGTH_LONG)
          .show();
    }
  }
Esempio n. 26
0
 /** 创建快捷方式 * */
 public void createDeskShortCut() {
   // 创建快捷方式的Intent
   Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
   // 不允许重复创建 ,如果重复的话就会有多个快捷方式了
   shortcutIntent.putExtra("duplicate", false);
   // 这个就是应用程序图标下面的名称
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.lable));
   // 快捷图片
   Parcelable icon =
       Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.logo1);
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
   // 这个MainActivity是调用此方法的Activity
   Intent intent = new Intent(getApplicationContext(), StartActivity.class);
   // 下面两个属性是为了当应用程序卸载时桌面 上的快捷方式会删除
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   // 点击快捷图片,运行的程序主入口
   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
   // 最后一步就是发送广播
   sendBroadcast(shortcutIntent);
   // Toast.makeText(this, "已在手机屏幕创建快捷方式", Toast.LENGTH_LONG).show();
 }
Esempio n. 27
0
  private void addShortcut() {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra("duplicate", false);
    ComponentName comp = new ComponentName(this.getPackageName(), "." + this.getLocalClassName());
    Intent intent = new Intent(Intent.ACTION_MAIN).setComponent(comp);
    // Bundle bundle = new Bundle();
    // bundle.putString("info", "infohahaha"+time);
    // bundle.putString("info", "infohahaha");
    // intent.putExtras(bundle);
    intent.putExtra("type", accountType);
    intent.putExtra("sourceId", sourceId);
    intent.putExtra("sourceImage", sourceImageURL);
    intent.putExtra("sourceName", sourceName);
    intent.putExtra("contentUrl", contentUrl); // for rss

    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, sourceName);

    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    sendBroadcast(shortcut);
  }
Esempio n. 28
0
  private void addShortcut() {
    // Context mContext = MainActivity.this;
    SharedPreferences appPreferences;
    boolean isAppInstalled = false;

    appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    isAppInstalled = appPreferences.getBoolean("isAppInstalled", false);
    if (isAppInstalled == false) {
      Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
      shortcutIntent.setAction(Intent.ACTION_MAIN);
      Intent addIntent = new Intent();
      addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
      addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "DPPePOS");
      addIntent.putExtra(
          Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
          Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
      addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
      getApplicationContext().sendBroadcast(addIntent);
    }
    // finally isAppInstalled should be true.
    SharedPreferences.Editor editor = appPreferences.edit();
    editor.putBoolean("isAppInstalled", true);
    editor.commit();
  }
Esempio n. 29
0
  /** 为程序创建桌面快捷方式 */
  public static void addShortcut(Context context) {
    if (hasShortcut(context)) return;
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    // 快捷方式的名称
    shortcut.putExtra(
        Intent.EXTRA_SHORTCUT_NAME, context.getResources().getString(R.string.app_name));
    shortcut.putExtra("duplicate", false); // 不允许重复创建

    /** **************************此方法已失效************************ */
    // ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
    // shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new
    // Intent(Intent.ACTION_MAIN).setComponent(comp));
    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(context, context.getClass().getName());
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    // 快捷方式的图标
    ShortcutIconResource iconRes =
        Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_launcher);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

    context.sendBroadcast(shortcut);
  }
  public void createShortcut(String name, String fromAddress, String toAddress) {
    // The meat of our shortcut
    Intent shortcutIntent = new Intent(); // "com.omareitti.MainApp");
    shortcutIntent.setClassName(getPackageName(), MainApp.class.getName());
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    if (toAddress != null) shortcutIntent.putExtra("toAddress", toAddress);
    if (fromAddress != null) shortcutIntent.putExtra("fromAddress", fromAddress);

    // The result we are passing back from this activity
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    intent.putExtra(
        Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
        Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

    setResult(RESULT_OK, intent);

    finish(); // Must call finish for result to be returned immediately
  }