0

I have a word document(.doc or .docx) in the server. I need to open in my android application by clicking one button .doc file have to open. How to do this? anyone, please help me.

I tried this code :

File file = new File(Environment.getExternalStorageDirectory(),
                    "Document.docx");
            try {
                if (file.exists()) {
                    Uri path = Uri.fromFile(file);
                    Intent objIntent = new Intent(Intent.ACTION_VIEW);
                    // replace "application/msword" with
                    // "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
                    // for docx files
                    // objIntent.setDataAndType(path,"application/msword");
                    objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(objIntent);
                } else {
                    Toast.makeText(PMComplitionProjectActivity.this, "File NotFound",
                            Toast.LENGTH_SHORT).show();
                }
            } catch (ActivityNotFoundException e) {
                Toast.makeText(PMComplitionProjectActivity.this,
                        "No Viewer Application Found", Toast.LENGTH_SHORT)
                        .show();
            } catch (Exception e) {
                e.printStackTrace();
            }
plase
  • 361
  • 1
  • 3
  • 9
madhu
  • 35
  • 1
  • 9
  • can you show us some of your code that perhaps didnt work? – letsCode Jul 03 '18 at 12:45
  • 1
    Possible duplicate of [Android how to open a .doc extension file?](https://stackoverflow.com/questions/10242306/android-how-to-open-a-doc-extension-file) – livemaker Jul 03 '18 at 12:47
  • Possible duplicate of [Open a selected file (image, pdf, ...) programmatically from my Android Application?](https://stackoverflow.com/questions/19422075/open-a-selected-file-image-pdf-programmatically-from-my-android-applicat) – Gowthaman M Jul 03 '18 at 12:47

1 Answers1

2

I have this link that shows how to open any file in Android : http://www.androidsnippets.com/open-any-type-of-file-with-default-intent.html

Also, there is a similar case, which is done by PDF file : Android : how to open pdf file from server in android

I hope these links will work for you.

Good Luck, G.

  • I tried with your first link code. It showing Can't open file something wrong for doc and pdf files. – madhu Jul 04 '18 at 06:10