Skip to content Skip to sidebar Skip to footer

Why It Is Not Opening Defined Folder Via Intent In Android?

This code is redirecting to drive with open navigation but not opening actual given path OLD Code Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + '/fold

Solution 1:

private static final int READ_REQUEST_CODE = 10;
...
/**
 * Fires an intent to spin up the "file chooser" UI and select an image.
 */
public void performFileSearch() {

    Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.setType(uri, "text/*");

    startActivityForResult(intent, READ_REQUEST_CODE);
}

After the user selects a document in the picker, onActivityResult() gets called. The resultData parameter contains the URI that points to the selected document. Extract the URI using getData(). When you have it, you can use it to retrieve the document the user wants.

@Override
public void onActivityResult(int requestCode, int resultCode,
        Intent resultData) {

    if (requestCode == READ_REQUEST_CODE && resultCode == Activity.RESULT_OK) {

        Uri uri = null;
        if (resultData != null) {
            uri = resultData.getData();
            Log.i(TAG, "Uri: " + uri.toString());
            showImage(uri);
        }
    }
}

Post a Comment for "Why It Is Not Opening Defined Folder Via Intent In Android?"