0

I would like to open a local PDF file with a pre-installed PDF-viewer via Share-Intent like this:

Uri uri= Uri.parse("file:///android_asset/manual.pdf");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setType("application/pdf");
startActivity(intent);

The app-picker is shown, when I click on Adobe PDF it doesn't show the PDF-file however.

Am I doing something wrong, or is it simply not possible?

deimos1988
  • 5,896
  • 7
  • 41
  • 57
  • where you have kept the pdf file. is it in assets? The path you are passing is wrong. It is failing to open the file from that path. – Raghavendra Apr 22 '15 at 11:05
  • Yes, my file is located in the assets-folder - when I inspected the uri, it looked fine. – deimos1988 Apr 22 '15 at 11:07
  • follow this link http://stackoverflow.com/questions/17085574/read-a-pdf-file-from-assets-folder to open a pdf from assets. – Raghavendra Apr 22 '15 at 11:08

2 Answers2

0

This worked for me,

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory()+"/directory/"+theNamesOfFiles)),"application/pdf");   
intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
Sree
  • 3,136
  • 2
  • 31
  • 39
Karthika PB
  • 1,373
  • 9
  • 16
0

You have 2 options:

  1. Put the file in a public storage where the PDF viewer app can access it
  2. Use a ContentProvider class to give that PDF viewer access to a private file.

See: How to copy files from 'assets' folder to sdcard? http://developer.android.com/guide/topics/providers/content-provider-creating.html

Community
  • 1
  • 1
marmor
  • 27,641
  • 11
  • 107
  • 150