user468311
user468311

Reputation:

Doc, ppt, xls mime type

I try to open doc, ppt, xls and pfg files with app installed via intent. For pdf I use i.setDataAndType(Uri.fromFile(file), "application/pdf"); but if I do following:

i.setDataAndType(Uri.fromFile(file), "application/doc");

I receive exception, saying that there are no apps, that can handle intent. What am I doing wrong? I've got QuickOffice installed, so I think it could open file.

Upvotes: 5

Views: 7849

Answers (2)

Shiv
Shiv

Reputation: 1267

Another way to get exact mime type from file path or URL is:

String mimeType = URLConnection.guessContentTypeFromName(url);

Upvotes: 0

dfjacobs
dfjacobs

Reputation: 1065

Here's a link to the 'official' mime types for Microsoft Office files. You'll probably have better luck if you use "application/msword" in place of "application/doc".

You can also have the OS try to determine the appropriate mime type for a file:

String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(url));

Hopefully any application that registers a mime type that it can handle will cause the mime type map to be updated.

Upvotes: 18

Related Questions