I am trying to create an app that will let you view a stored PDF, like a simple file reader.
I am using a Navigational Drawer Project Base and I cannot seem to get the PDF to open.
I stored a test PDF in assets/ and I have also tried in raw/. If I try it with assets/ it crashes whenever I try to open the PDF on the device, saying "Cannot display PDF (test.pdf cannot be opened).
I have tried a few ways to try and get this to work but none have prevailed, here is my code as of now:
public void onSectionAttached(int number){
switch (number) {
case 1:
mTitle = getString(R.string.title_song);
File pdfFile = new File("/assets/test.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(intent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(MainActivity.this, "It didn't crash!", Toast.LENGTH_LONG).show();
}
break;
case 2:
mTitle = getString(R.string.title_artist);
break;
}
}