简体   繁体   中英

Files are not selectable on Intent.ACTION_GET_CONTENT

I want to attach a text file of any format in my app. So i have written the following code. The problem is that, i cannot select files from any folder. But if go through any file manager (eg : ES file explorer), i can access those files. I have also attached screenshot please see that to get clear idea.

文件在下载文件夹中显示为灰色

通过文件管理器打开文件时可以选择文件

Below is the code i have used.

void pickDocument() {

        Intent documentIntent;

        documentIntent = new Intent(Intent.ACTION_GET_CONTENT);

        documentIntent.setType("text/*");

        startActivityForResult(documentIntent, PICK_DOCUMENTS);
}

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

        super.onActivityResult(requestCode, resultCode, data);

        try {

            if (resultCode != Activity.RESULT_OK)
                return;

            switch (requestCode) {

                case PICK_DOCUMENTS:

                    Uri documentUri = data.getData();

                    if (mChooseFileDialogListener != null) {

                        mChooseFileDialogListener.onDocumentClick(documentUri, ViewModel.FILE_TYPE);

                    }

                    break;

            }

        } 

}

Try Replacing

 documentIntent.setType("text/*");

with

documentIntent.setType("*/*");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM