Пример #1
0
  private void onFinished(Uri... uris) {
    final Intent intent = new Intent();
    if (uris.length == 1) {
      intent.setData(uris[0]);
    } else if (uris.length > 1) {
      final ClipData clipData = new ClipData(null, mState.acceptMimes, new ClipData.Item(uris[0]));
      for (int i = 1; i < uris.length; i++) {
        clipData.addItem(new ClipData.Item(uris[i]));
      }
      intent.setClipData(clipData);
    }

    if (mState.action == ACTION_GET_CONTENT) {
      intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    } else if (mState.action == ACTION_OPEN_TREE) {
      intent.addFlags(
          Intent.FLAG_GRANT_READ_URI_PERMISSION
              | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
              | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
              | Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
    } else {
      intent.addFlags(
          Intent.FLAG_GRANT_READ_URI_PERMISSION
              | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
              | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);
    }

    setResult(Activity.RESULT_OK, intent);
    finish();
    Log.d(TAG, "onFinished: uri=" + Arrays.toString(uris) + ", data=" + intent);
  }
  @Override
  public boolean onLongClick(View v) {
    // Create a new ClipData.Item from the ImageView object's generateTag
    ClipData data = ClipData.newPlainText("id", String.valueOf(sousTache.getId()));
    data.addItem(new ClipData.Item(sousTache.getEtat().name()));
    View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(v);
    v.startDrag(data, shadowBuilder, v, 0);
    v.setVisibility(View.INVISIBLE);

    return true;
  }