Is there any way to read local pdf file using google docs

I saw a way to read online pdf files using google docs ...

Android - Download PDF / PDF Viewer

Can I use it to view local files stored on an SD card.

+3
source share
1 answer

You can run an intent that will allow the user to choose which application will open the PDF, with the following code that will work for any file and mimetype. If the user does not have an application that can open it, you can display an error message or do whatever you need.

, , , .

private void openFile(File f, String mimeType)
{
    Intent viewIntent = new Intent();
    viewIntent.setAction(Intent.ACTION_VIEW);
    viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
    // using the packagemanager to query is faster than trying startActivity
    // and catching the activity not found exception, which causes a stack unwind.
    List<ResolveInfo> resolved = getPackageManager().queryIntentActivities(viewIntent, 0);
    if(resolved != null && resolved.size() > 0)
    {
        startActivity(viewIntent);
    }
    else
    {
        // notify the user they can't open it.
    }
}
0

Source: https://habr.com/ru/post/1794628/


All Articles