Android How to view doc with sdcard in gallery?

I have an application in which the user can search for images, audio, video, a doc file with SDCard and select 1 file to upload to the server. Using the code below, I can open the gallery and select an image, audio, video. But I do not know how to search for a document from the gallery.

Here is my code.

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);
    //intent.setType("video/*");
    //intent.setType("audio/*");
    //intent.setType("image/*");
    //**What I have to do for view document[.pdf/text/doc] file**
    startActivityForResult(Intent.createChooser(intent, "Complete action using"), REQUEST_CODE);

Does anyone know how this can be achieved? Any help is appreciated.

+5
source share
3 answers

try this aFileChooser library  its working tone

Pls see link

+1
source

Hope this helps you open the document

public void openDOC(String name) {


        File file = new File(Environment.getExternalStorageDirectory() + "/"
                + bmodel.getUserMasterBO().getUserid() + "/" + name);
        if (file.exists()) {
            Uri path = Uri.fromFile(file);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/msword");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            try {
                startActivity(intent);
            } catch (ActivityNotFoundException e) {
                Toast.makeText(this, "No Application Available to View DOC",
                        Toast.LENGTH_SHORT).show();
            }
        }

    }
0
source

:

File docfolder = new File(Environment.getExternalStorageDirectory() + "/"
                + "Documents/");
File docList[] = docfolder.listFiles();
for(int i=0;i<docList.length;i++)
{   
        if (docList[i].exists()) {
            Uri path = Uri.fromFile(docList[i]);
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(path, "application/msword");
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

            try {
                startActivity(intent);
            }
             catch (ActivityNotFoundException e) {

            }
        }
}
0

All Articles