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);  
Answer from ρяσѕρєя K on Stack Overflow
🌐
GitHub
github.com › IlyaFinkelshteyn › XamDocumentViewer
GitHub - IlyaFinkelshteyn/XamDocumentViewer: This app can open Doc, Docx files on Android, IOS and Windows UWP.
This app can open Doc, Docx files on Android, IOS and Windows UWP. - IlyaFinkelshteyn/XamDocumentViewer
Author   IlyaFinkelshteyn
🌐
Adu-usa
adu-usa.org › jagmb › how-to-open-doc-file-in-android-programmatically-github
how to open doc file in android programmatically github
Have to go to GitHub and create a basic hello world Android app open a Word.doc on... File programmatically in Android ] Gradle properties file in app\src\main\assetspath.You can customise according to need!, Share this with your friends Tweet and find the ZIP file selected with Key...
🌐
CopyProgramming
copyprogramming.com › howto › how-to-open-doc-file-in-android-programmatically
Android: Programmatically Accessing Doc Files on Android: A Guide
March 23, 2023 - The link provided directs to the GitHub repository for AndroidDocxToHtml developed by Plutext. Access documents and other files from shared storage, In these cases, allow the user to choose the file to open by invoking the ACTION_OPEN_DOCUMENT intent, which opens the system's file picker app.
🌐
GitHub
github.com › Asutosh11 › DocumentReader
GitHub - Asutosh11/DocumentReader: This library reads word documents (.doc and .docx), txt and PDF files, and gives the output content of the document as a String.
/* Even if you don't know your file type, this library detects the file mime type and gives you the content of the file as a String */ val docString : String = when (DocumentReaderUtil.getMimeType(fileUri, applicationContext)) { "text/plain" -> DocumentReaderUtil.readTxtFromUri(fileUri, applicationContext) "application/pdf" -> DocumentReaderUtil.readPdfFromUri(fileUri, applicationContext) "application/msword" -> DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext) "application/vnd.openxmlformats-officedocument.wordprocessingml.document" -> DocumentReaderUtil.readWordDocFromUri(fileUri, applicationContext) else -> "" }
Starred by 100 users
Forked by 17 users
Languages   Kotlin 100.0% | Kotlin 100.0%
🌐
GitHub
github.com › MindorksOpenSource › Open-PDF-File-Android-Example
GitHub - MindorksOpenSource/Open-PDF-File-Android-Example: An example project to demonstrate how to open a PDF file in Android programmatically · GitHub
An example project to demonstrate how to open a PDF file in Android programmatically - MindorksOpenSource/Open-PDF-File-Android-Example
Starred by 70 users
Forked by 18 users
Languages   Kotlin
🌐
GitHub
github.com › topics › docx
docx · GitHub Topics
android pdf application viewer excel powerpoint reader pdf-viewer docx document pptx excelreader hacktoberfest powerpoint-presentations ppt ... java pdf library office docx thumbnail-generator pdf-thumbnail java-thumbnail mpeg-thumbnail mp3-thumbnail office-thumbnail ... This library reads any type of documents like (doc, docx, xls, xlsx, ppt, pptx,pdf, rtf, csv, json, html, xml,txt,and kotlin)F files.
🌐
GitHub
github.com › topics › office
office · GitHub Topics
android pdf mobile excel word office fileviewer filereader ppt
Top answer
1 of 10
36

Try the below code. I am using this code for opening a PDF file. You can use it for other files also.

File file = new File(Environment.getExternalStorageDirectory(),
                     "Report.pdf");
Uri path = Uri.fromFile(file);
Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW);
pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pdfOpenintent.setDataAndType(path, "application/pdf");
try {
    startActivity(pdfOpenintent);
}
catch (ActivityNotFoundException e) {

}

If you want to open files, you can change the setDataAndType(path, "application/pdf"). If you want to open different files with the same intent, you can use Intent.createChooser(intent, "Open in...");. For more information, look at How to make an intent with multiple actions.

2 of 10
34

Use this code ,which helped me to open all types of files ...

 private void openFile(File url) {

    try {

        Uri uri = Uri.fromFile(url);

        Intent intent = new Intent(Intent.ACTION_VIEW);
        if (url.toString().contains(".doc") || url.toString().contains(".docx")) {
            // Word document
            intent.setDataAndType(uri, "application/msword");
        } else if (url.toString().contains(".pdf")) {
            // PDF file
            intent.setDataAndType(uri, "application/pdf");
        } else if (url.toString().contains(".ppt") || url.toString().contains(".pptx")) {
            // Powerpoint file
            intent.setDataAndType(uri, "application/vnd.ms-powerpoint");
        } else if (url.toString().contains(".xls") || url.toString().contains(".xlsx")) {
            // Excel file
            intent.setDataAndType(uri, "application/vnd.ms-excel");
        } else if (url.toString().contains(".zip")) {
            // ZIP file
            intent.setDataAndType(uri, "application/zip");
        } else if (url.toString().contains(".rar")){
            // RAR file
            intent.setDataAndType(uri, "application/x-rar-compressed");
        } else if (url.toString().contains(".rtf")) {
            // RTF file
            intent.setDataAndType(uri, "application/rtf");
        } else if (url.toString().contains(".wav") || url.toString().contains(".mp3")) {
            // WAV audio file
            intent.setDataAndType(uri, "audio/x-wav");
        } else if (url.toString().contains(".gif")) {
            // GIF file
            intent.setDataAndType(uri, "image/gif");
        } else if (url.toString().contains(".jpg") || url.toString().contains(".jpeg") || url.toString().contains(".png")) {
            // JPG file
            intent.setDataAndType(uri, "image/jpeg");
        } else if (url.toString().contains(".txt")) {
            // Text file
            intent.setDataAndType(uri, "text/plain");
        } else if (url.toString().contains(".3gp") || url.toString().contains(".mpg") ||
                url.toString().contains(".mpeg") || url.toString().contains(".mpe") || url.toString().contains(".mp4") || url.toString().contains(".avi")) {
            // Video files
            intent.setDataAndType(uri, "video/*");
        } else {
            intent.setDataAndType(uri, "*/*");
        }

        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, "No application found which can open the file", Toast.LENGTH_SHORT).show();
    }
}
Find elsewhere
🌐
GitHub
github.com › opendocument-app › OpenDocument.droid
GitHub - opendocument-app/OpenDocument.droid: It's Android's first OpenOffice Document Reader! · GitHub
It's Android's first OpenOffice Document Reader! Contribute to opendocument-app/OpenDocument.droid development by creating an account on GitHub.
Starred by 408 users
Forked by 41 users
Languages   HTML 85.6% | Java 12.7% | C++ 1.2% | HCL 0.3% | Python 0.1% | Ruby 0.1%
🌐
GitHub
github.com › SufficientlySecure › document-viewer
GitHub - SufficientlySecure/document-viewer: Document Viewer is a highly customizable document viewer for Android. · GitHub
Document Viewer is a highly customizable document viewer for Android. - SufficientlySecure/document-viewer
Starred by 534 users
Forked by 158 users
Languages   Java 44.6% | PHP 40.0% | HTML 12.1% | C 1.6% | C++ 0.6% | Hack 0.4%
🌐
GitHub
github.com › Victor2018 › DocViewer
GitHub - Victor2018/DocViewer: android DocViewer support view word excel ppt pdf txt image in sdcard & uri & assets & url · GitHub
build file: allprojects { repositories { ... maven { url "https://jitpack.io" } } } or setting file: dependencyResolutionManagement { repositories { ... maven { url "https://jitpack.io" } } } Step 2. Add the dependency · dependencies { implementation 'com.github.Victor2018:DocViewer:latestVersion' } Step 3. set layoutManager for recyclerView by kotlin · DocViewerActivity.launchDocViewer(this,docSourceType,path)
Starred by 133 users
Forked by 40 users
Languages   Java 98.8% | Kotlin 1.2%
🌐
Medium
medium.com › @aahsanaahmed26 › retrieving-and-displaying-docx-files-from-android-device-in-android-studio-step-by-step-tutorial-4a6a6fa280fd
Retrieving and Displaying Docx Files from Android Device in Android Studio: Step-by-Step Tutorial | by Ahsan Ahmed | Medium
November 30, 2024 - Don’t forget to subscribe to our YouTube channel for more exciting tutorials on Android app development. Now, go ahead and create an amazing document file browsing experience for your app users. Happy coding! Source Code: https://github.com/AhsanAhmed03/Get-Docx-Files-Android
🌐
Mindorks
blog.mindorks.com › how-to-open-a-pdf-file-in-android-programmatically
How to open a PDF file in Android programmatically? - MindOrks
June 17, 2019 - So, you can put that document in the assets folder and use it. From Device: The other way of opening a PDF is to open it from the device itself. Here, you can open the PDF files present in your mobile device.
🌐
GitHub
github.com › praharshjain › Vudit
GitHub - praharshjain/Vudit: A file viewer for Android · GitHub
A file viewer for Android. Contribute to praharshjain/Vudit development by creating an account on GitHub.
Starred by 62 users
Forked by 17 users
Languages   JavaScript 85.9% | Java 10.2% | CSS 2.2% | HTML 1.7%
🌐
YouTube
youtube.com › watch
How to Open .Docx File in Android - YouTube
How to Open .Docx File in Androidiss Video me maine bataya hai agar apke phone me .docx ki file open nahi ho rahi hai to .docx ki file ko kaise open kare to ...
Published   September 21, 2020
Top answer
1 of 4
31

I think you should use custom library for getting that done .See this and this

But there is a way for displaying PDF with out calling another application

This is a way for showing PDF in android app that is embedding the PDF document to android webview using support from http://docs.google.com/viewer

pseudo

String doc="<iframe src='http://docs.google.com/viewer?url=+location to your PDF File+' 
              width='100%' height='100%' 
              style='border: none;'></iframe>";

a sample is is shown below

 String doc="<iframe src='http://docs.google.com/viewer?url=http://www.iasted.org/conferences/formatting/presentations-tips.ppt&embedded=true' 
              width='100%' height='100%' 
              style='border: none;'></iframe>";

Code

    WebView  wv = (WebView)findViewById(R.id.webView); 
    wv.getSettings().setJavaScriptEnabled(true);
    wv.getSettings().setPluginsEnabled(true);
    wv.getSettings().setAllowFileAccess(true);
    wv.loadUrl(doc);
    //wv.loadData( doc, "text/html",  "UTF-8");

and in manifest provide

<uses-permission android:name="android.permission.INTERNET"/>

See this

Caution : I am not aware of compatibility issues with various android versions

In this approach the drawback is you need internet connectivity . But i think it satisfy your need

EDIT Try this as src for iframe

src="http://docs.google.com/gview?embedded=true&url=http://www.pc-hardware.hu/PDF/konfig.pdf"

try wv.loadData( doc , "text/html", "UTF-8"); . Both works for me

2 of 4
4

Download the source code from here (Display PDF file inside my android application)

Add this dependency in your Grade:

compile 'com.github.barteksc:android-pdf-viewer:2.0.3'

activity_main.xml

<RelativeLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    xmlns:android="http://schemas.android.com/apk/res/android" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:background="@color/colorPrimaryDark"
        android:text="View PDF"
        android:textColor="#ffffff"
        android:id="@+id/tv_header"
        android:textSize="18dp"
        android:gravity="center"></TextView>

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_below="@+id/tv_header"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>


    </RelativeLayout>

MainActivity.java

package pdfviewer.pdfviewer;

import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.provider.OpenableColumns;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.barteksc.pdfviewer.PDFView;
import com.github.barteksc.pdfviewer.listener.OnLoadCompleteListener;
import com.github.barteksc.pdfviewer.listener.OnPageChangeListener;
import com.github.barteksc.pdfviewer.scroll.DefaultScrollHandle;
import com.shockwave.pdfium.PdfDocument;

import java.util.List;

public class MainActivity extends Activity implements OnPageChangeListener,OnLoadCompleteListener{
    private static final String TAG = MainActivity.class.getSimpleName();
    public static final String SAMPLE_FILE = "android_tutorial.pdf";
    PDFView pdfView;
    Integer pageNumber = 0;
    String pdfFileName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);


        pdfView= (PDFView)findViewById(R.id.pdfView);
        displayFromAsset(SAMPLE_FILE);
    }

    private void displayFromAsset(String assetFileName) {
        pdfFileName = assetFileName;

        pdfView.fromAsset(SAMPLE_FILE)
                .defaultPage(pageNumber)
                .enableSwipe(true)

                .swipeHorizontal(false)
                .onPageChange(this)
                .enableAnnotationRendering(true)
                .onLoad(this)
                .scrollHandle(new DefaultScrollHandle(this))
                .load();
    }


    @Override
    public void onPageChanged(int page, int pageCount) {
        pageNumber = page;
        setTitle(String.format("%s %s / %s", pdfFileName, page + 1, pageCount));
    }


    @Override
    public void loadComplete(int nbPages) {
        PdfDocument.Meta meta = pdfView.getDocumentMeta();
        printBookmarksTree(pdfView.getTableOfContents(), "-");

    }

    public void printBookmarksTree(List<PdfDocument.Bookmark> tree, String sep) {
        for (PdfDocument.Bookmark b : tree) {

            Log.e(TAG, String.format("%s %s, p %d", sep, b.getTitle(), b.getPageIdx()));

            if (b.hasChildren()) {
                printBookmarksTree(b.getChildren(), sep + "-");
            }
        }
    }

}

Thanks!

🌐
Android Developers
developer.android.com › core areas › app data and files › access documents and other files from shared storage
Access documents and other files from shared storage | App data and files | Android Developers
In these cases, allow the user to choose the file to open by invoking the ACTION_OPEN_DOCUMENT intent, which opens the system's file picker app. To show only the types of files that your app supports, specify a MIME type.