First I would like to say that I have tried several solutions, methods, suggestions and referred to several links on here to open a PDF. You can call me slow, but I have at least tried. I would like to open a PDF in my Android Application. I am on a Nexus 10 tablet. I cannot use a web view. I want to open this pdf via my OnClickListener in one of my fragments. I think my biggest problem is I am unsure where to save my PDF. I have tried res and assets folders. Many example use /sdcard/ - is that just saving it on my device? If so where / how to get path? I have saved a .pdf file in adobe reader on my tablet can I access that path? I am using API min 16 target API 19.
I have tried many variations of this
public void onClick(View v)
{
switch(v.getId())
{
case R.id.bizbro3:
File pdfFile = new File( // I don't know what to put here / where to save pdf. Have tried /sdcard/ , getresrouces, absolutepath, ect.);
if(pdfFile.exists())
{
Uri path = Uri.fromFile(pdfFile);
Intent pdfIntent = new Intent(Intent.ACTION_VIEW);
pdfIntent.setDataAndType(path, "application/pdf");
pdfIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
try
{
startActivity(pdfIntent);
}
catch(ActivityNotFoundException e)
{
Toast.makeText(v.getContext(), "Something went wrong. Returning to the Main Menu",
Toast.LENGTH_LONG).show();
fragment = new FragmentThree();
fragment.setArguments(args);
FragmentManager frgManager = getFragmentManager();
frgManager.beginTransaction().replace(R.id.content_frame, fragment)
.commit();
}
}
}