Android – How do I open a file in another app via Intent?

Posting my changes here in case it can help someone else. I ended up changing the download location to an internal folder and adding a content provider.

public void open_file(String filename) {
    File path = new File(getFilesDir(), "dl");
    File file = new File(path, filename);

    // Get URI and MIME type of file
    Uri uri = FileProvider.getUriForFile(this, App.PACKAGE_NAME + ".fileprovider", file);
    String mime = getContentResolver().getType(uri);

    // Open file with user selected app
    Intent intent = new Intent();
    intent.setDataAndType(uri, mime);

Leave a Comment