После сниппет может помочь вам доступ к файлам из asset
папки, а затем открыть его:
private void ReadFromAssets()
{
AssetManager assetManager = getAssets();
InputStream in = null;
OutputStream out = null;
File file = new File(getFilesDir(), "file.pdf");
try
{
in = assetManager.open("file.pdf");
out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);
copyFile(in, out);
in.close();
in = null;
out.flush();
out.close();
out = null;
} catch (Exception e)
{
Log.e("tag", e.getMessage());
}
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(
Uri.parse("file://" + getFilesDir() + "/file.pdf"),
"application/pdf");
startActivity(intent);
}
и copyFile
метод следующим образом:
private void copyFile(InputStream in, OutputStream out) throws IOException
{
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1)
{
out.write(buffer, 0, read);
}
}
EDIT
Для этой цели вам нужно будет использовать экстернальную библиотеку. Это объясняется довольно хорошо по ссылке ниже: Render a PDF file using Java on Android
Надеюсь, это поможет вам.
Вы рассмотрели копирование файлов из папки средств на SD-карту? – Pallavi
да, я пробовал это – Goofy
Check [this] (https://stackoverflow.com/questions/47647784/trying-to-open-pdf-file-from-assets-folder-using-fileprovider-but-it-gives- filen? answertab = active # tab-top "это поможет вам")! один –