-1

I want a direct path to the assets folder so I can open a PDF that is stored there. So I can pass it as a parameter in this Intent:

Intent i = new Intent(this, SecondMainActivity.class);
i.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME, "path_to_assets_folder");
startActivity(i);
Bouss
  • 205
  • 2
  • 9
  • 20

2 Answers2

0

Try this;

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/yourfile.pdf"),
                "application/pdf");
startActivity(intent);

also you can check this: Read a pdf file from assets folder

Community
  • 1
  • 1
Oğuzhan Döngül
  • 7,856
  • 4
  • 38
  • 52
0

from Android Developer guide,

public final AssetManager getAssets ()

Added in API level 1
Retrieve underlying AssetManager storage for these resources. 

so, you can use getAssets,

AssetManager mngr = getAssets();

To access a file in assets folder,

InputStream is = mngr.open("file name");

If your class is not an Activity, you'll need to pass a context into it and then call getAssets on that.

public myClass(Context myContext) {
    AssetManager mngr = myContext.getAssets();
    InputStream is = mngr.open("file name");
}
Sufiyan Ghori
  • 18,164
  • 14
  • 82
  • 110