Android如何在gallery中查看sdcard的doc?

时间:2012-05-24 13:27:41

标签: android search gallery document sd-card

我有应用程序,用户可以从sdcard搜索图像,音频,视频,doc文件,并选择1个文件在服务器上传。 使用下面的代码我可以打开图库并选择图像,音频,视频但我不知道如何从图库中搜索文档。

这是我的代码。

    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);

有谁知道如何实现这一目标?非常感谢任何帮助。

3 个答案:

答案 0 :(得分:1)

试试这个库 aFileChooser  工作正常

请参阅此link

答案 1 :(得分:0)

希望这可以帮助您打开文档

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();
            }
        }

    }

答案 2 :(得分:0)

尝试以下方法,

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) {

            }
        }
}