示例#1
0
  /**
   * Set share intent
   *
   * @param selectedItems
   * @return shared intent
   */
  public static Intent createShareIntent(ArrayList<MediaObject> selectedItems) {
    final ArrayList<Uri> uris = new ArrayList<Uri>();
    final Intent intent = new Intent();
    int mediaType = 0;
    String mimeType = "image/*";

    for (int i = 0; selectedItems.size() > i; i++) {
      if (uris.size() >= 1000) break;
      mediaType = selectedItems.get(i).getType();
      mimeType = (mediaType == MediaItem.IMAGE) ? "image/*" : "video/*";

      MediaItem item = (MediaItem) selectedItems.get(i);
      Uri uri = ContentUris.withAppendedId(item.getUri(mediaType), item.getId());
      uris.add(uri);
    }

    final int size = uris.size();
    if (size > 0) {

      if (size > 1) {
        intent.setAction(Intent.ACTION_SEND_MULTIPLE).setType(mimeType);
        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
      } else {
        intent.setAction(Intent.ACTION_SEND).setType(mimeType);
        intent.putExtra(Intent.EXTRA_STREAM, uris.get(0));
      }
      intent.setType(mimeType);
    }

    return intent;
  }
示例#2
0
  /**
   * Set share intent
   *
   * @param mediaItems - selectedItems
   * @param position - item position
   * @return shared intent
   */
  public static Intent createShareIntent(ArrayList<MediaItem> mediaItems, int position) {
    final Intent intent = new Intent();
    String mimeType = "image/*";

    if (position >= mediaItems.size()) {
      position = mediaItems.size() - 1;
    }

    MediaItem item = mediaItems.get(position);
    mimeType = (item.getType() == MediaItem.IMAGE) ? "image/*" : "video/*";

    long id = item.getId();
    Uri uri = ContentUris.withAppendedId(item.getUri(item.getType()), id);

    intent.setAction(Intent.ACTION_SEND).setType(mimeType);
    intent.putExtra(Intent.EXTRA_STREAM, uri);
    intent.setType(mimeType);

    return intent;
  }
示例#3
0
  /**
   * Link folder Create shortcut icon in HomeScreen
   *
   * @param context {@link Context}
   * @param selectedItem - selected folder
   */
  public static void linkFolder(Context context, FolderItem selectedItem) {
    MediaItem[] thubmItems = selectedItem.getImages();
    MediaItem item = thubmItems[0];
    String albumName = selectedItem.getDisplayName();
    Bitmap albumImage = ThumbnailCache.INSTANCE.getFolderBitmap(item.getId());
    Bitmap scaledAlbumImage = Bitmap.createScaledBitmap(albumImage, 128, 128, true);
    Uri path = Uri.parse(String.valueOf(selectedItem.getPath()));
    String className = context.getClass().getName();
    String packageName = context.getPackageName();

    Intent shortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT);
    shortcutIntent.setClassName(packageName, className);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.setData(path);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, albumName);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, drawShortcutIcon(scaledAlbumImage));
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(intent);
  }