What I want to do is to have the user press a button of some sort and inside the method of that button I want the system to open up a file (in this case a .docx file) inside a file viewer this would have to be done via an intent but how should that be coded and where do I put my .docx file?
Asked
Active
Viewed 1,406 times
1 Answers
0
Android doesn't have inbuilt functionality for viewing .docx file.
for that,
Your android device should installed .docx viewer (Third party like, Documents To Go, Smart Office, Quickoffice) application then you can open that file using Intent
.
something like,
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
String type = "application/msword";
intent.setDataAndType(Uri.fromFile(docx file), type);
startActivity(intent);
But if any .docx viewer is not installed then you can direct user to first install that application using Android Market and then after download that app you can open your .docx file in it.
Or you can integrate .docx viewer functionality in application using third party library. I think Apache's docx4j is in java.

user370305
- 108,599
- 23
- 164
- 151
-
I assume tried this out but it's giving me an error. I placed my .docx file in /res/raw and named it test.docx. This is my code: Intent intent = new Intent(); intent.setAction(Intent.ACTION_VIEW); String type = "application/msword"; intent.setDataAndType(Uri.fromFile(R.raw.test), type); startActivity(intent); – SweSnow Jul 16 '12 at 11:59
-
Method'android.net.Uri.fromFile(java.io.File)'in 'android.net.Uri' can not be applied to '(int)' – SweSnow Jul 16 '12 at 12:05
-
Copy your .docx file from raw folder to sdcard or internal storage then pass uri of that copied file from that place.. It works.. – user370305 Jul 16 '12 at 12:06
-
How would I copy the file to the internal storage? And then should I replace the "R.raw.test" with something like "/sdcard/files"? – SweSnow Jul 16 '12 at 12:10
-
This may help you http://stackoverflow.com/questions/10548530/validating-and-reading-a-word-file-in-android – Jul 16 '12 at 12:28