Android如何在gallary中查看SD卡上的文档?
我有一个应用程序,用户可以从SD卡中搜索图像、音频、视频、文档文件,并选择1个文件上传到服务器上。 使用下面的代码,我可以打开图库并选择图像、音频、视频,但我不知道如何从图库中搜索文档 这是我的密码Android如何在gallary中查看SD卡上的文档?,android,search,gallery,document,sd-card,Android,Search,Gallery,Document,Sd Card,我有一个应用程序,用户可以从SD卡中搜索图像、音频、视频、文档文件,并选择1个文件上传到服务器上。 使用下面的代码,我可以打开图库并选择图像、音频、视频,但我不知道如何从图库中搜索文档 这是我的密码 Intent intent = new Intent(); intent.setAction(Intent.ACTION_GET_CONTENT); //intent.setType("video/*"); //intent.setType("audio/*");
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);
有人知道如何做到这一点吗?非常感谢您的帮助。希望这能帮助您打开文档
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();
}
}
}
试试下面的方法
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) {
}
}
}
File docfolder=新文件(Environment.getExternalStorageDirectory()+“/”
+“文件/”;
文件docList[]=docfolder.listFiles();
对于(inti=0;i请尝试此库aFileChooser
工作正常
请查看此谢谢您的回答。我想查看所有文件,然后我将选择单文件表单列表。我不想打开文档。我只需要一个路径,以便将其上载到服务器上。