0

我尝试实现一个类似浏览器的应用程序。
我想让它可以打开设备支持的任何格式文件。
我知道下面的代码可以打开特定的格式:

String mimetype = mime_type(FileName);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(File), mimetype);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);

public String mime_type(String name) {
String type = null;
String[] mime = {".htm\ttext/html", ".html\ttext/html", ".doc\tapplication/msword", ".ppt\tapplication/vnd.ms-powerpoint", ".xls\tapplication/vnd.ms-excel", 
                ".txt\ttext/plain", ".pdf\tapplication/pdf", ".xlsx\tapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet", 
                ".pptx\tapplication/vnd.openxmlformats-officedocument.presentationml.presentation", ".docx\tapplication/vnd.openxmlformats-officedocument.wordprocessingml.document"};
int i;
for(i = 0; i < mime.length; i++) {
if(name.toLowerCase().endsWith(mime[i].split("\t")[0])) {
return mime[i].split("\t")[1];
}
}
return type;
}

但是文件格式比我能列出的要多。
如果有任何方法可以为所有格式做到这一点?
或者列出所有让用户选择的应用程序的任何方法?

4

1 回答 1

0

我发现 set mimetype*/*可以到达它。
它将显示所有已安装的应用程序以供选择。

于 2012-07-02T06:46:48.507 回答