Exemplo n.º 1
1
  public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
      mState.stack.push(doc);
      mState.stackTouched = true;
      onCurrentDirectoryChanged(ANIM_DOWN);
    } else if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) {
      // Explicit file picked, return
      new ExistingFinishTask(doc.derivedUri).executeOnExecutor(getCurrentExecutor());
    } else if (mState.action == ACTION_CREATE) {
      // Replace selected file
      SaveFragment.get(fm).setReplaceTarget(doc);
    } else if (mState.action == ACTION_MANAGE) {
      // First try managing the document; we expect manager to filter
      // based on authority, so we don't grant.
      final Intent manage = new Intent(DocumentsContract.ACTION_MANAGE_DOCUMENT);
      manage.setData(doc.derivedUri);

      try {
        startActivity(manage);
      } catch (ActivityNotFoundException ex) {
        // Fall back to viewing
        final Intent view = new Intent(Intent.ACTION_VIEW);
        view.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        view.setData(doc.derivedUri);

        try {
          startActivity(view);
        } catch (ActivityNotFoundException ex2) {
          /// M: Show toast with enhance way.
          showToast(R.string.toast_no_application);
        }
      }
    }
  }