Is there any possible way to open a .doc extension file?
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.
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 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.
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);
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:"));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With