Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android how to open a .doc extension file?

Tags:

android

doc

Is there any possible way to open a .doc extension file?

like image 598
Narendra Avatar asked Apr 20 '12 07:04

Narendra


People also ask

How do I open .doc files?

You can open DOC files with Microsoft Word in Windows and macOS. Word is the best application for opening DOC files because it fully supports the formatting of Word documents, which includes text spacing and alignment, images, charts, and tables. The word processor is also available for Android and iOS devices.

Why can't I open a word DOC on my phone?

If a file won't open, a few things could be wrong: You don't have permission to view the file. You're signed in to a Google Account that doesn't have access. The correct app isn't installed on your phone.

What is .DOC extension file?

What is a DOC File? DOC file extension refers to a word processing document format. This binary file format is proprietary of Microsoft and is native to Microsoft's most popular word processing application, Microsoft Word. It's a plain text document format which can also contain hyperlinks, images, alignments, etc.


2 Answers

Unlike iOS, Android itself does not support rendering .doc or .ppt files. You are looking for a public intent that allows your app to reuse other apps' activities to display these document types. But this will only work for a phone that has an app installed that supports this Intent.

http://developer.android.com/guide/topics/intents/intents-filters.html

or if you have installed some app then use this Intent:

//Uri uri = Uri.parse("file://"+file.getAbsolutePath());
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
String type = "application/msword";
intent.setDataAndType(Uri.fromFile(file), type);
startActivity(intent);  
like image 176
ρяσѕρєя K Avatar answered Sep 21 '22 01:09

ρяσѕρєя K


Here is a method to take care of this for you:

public void openDocument(String name) {
    Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
    File file = new File(name);
    String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(Uri.fromFile(file).toString());
    String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
    if (extension.equalsIgnoreCase("") || mimetype == null) {
        // if there is no extension or there is no definite mimetype, still try to open the file
        intent.setDataAndType(Uri.fromFile(file), "text/*");
    } else {
        intent.setDataAndType(Uri.fromFile(file), mimetype);            
    }
    // custom message for the intent
    startActivity(Intent.createChooser(intent, "Choose an Application:"));
}
like image 38
Jared Burrows Avatar answered Sep 17 '22 01:09

Jared Burrows