Example usage for android.provider DocumentsContract ACTION_MANAGE_DOCUMENT

List of usage examples for android.provider DocumentsContract ACTION_MANAGE_DOCUMENT

Introduction

In this page you can find the example usage for android.provider DocumentsContract ACTION_MANAGE_DOCUMENT.

Prototype

String ACTION_MANAGE_DOCUMENT

To view the source code for android.provider DocumentsContract ACTION_MANAGE_DOCUMENT.

Click Source Link

Usage

From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java

public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked()+directory");
        }//from ww w  . j  a  v  a 2s. c om
        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
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        new ExistingFinishTask(doc.derivedUri).executeOnExecutor(getCurrentExecutor());

        //           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) {
        //                Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
        //            }            
    } else if (mState.action == ACTION_CREATE) {
        // Replace selected file
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        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.
        if (DEBUG) {
            Log.i(TAG, "onDocumentPicked() " + mState.action);
        }
        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) {
                Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
            }
        }
    }
}

From source file:com.android.documentsui.DocumentsActivity.java

public void onDocumentPicked(DocumentInfo doc) {
    final FragmentManager fm = getFragmentManager();
    if (doc.isDirectory()) {
        mState.stack.push(doc);// w w  w  .j a va 2 s. c o  m
        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) {
                Toast.makeText(this, R.string.toast_no_application, Toast.LENGTH_SHORT).show();
            }
        }
    }
}