-2

I'm currently working on making an Android app, but have been having some trouble. I want to be able to push a button with the title of the document as it's TextView and then have that document open to be read. I've looked around for guides but everything I've found is either out of date or doesn't explain any of the code shown. Does anyone know how I can put such a thing in my app? At this point, I'm not even sure where to start with the process.

Note, I'm working in Java not Kotlin.

UPDATE: I was directed to a solution using intents. Now there seems to be an issue loading the file. My code is this:

public class atotf_pdf extends literature {

File file = new File("/storage/emulated/0/AToTF Preview.pdf");

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_main);

    Uri pdfURI = FileProvider.getUriForFile(atotf_pdf.this, "net.whispwriting.whispwriting.provider", file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(pdfURI, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
    startActivity(intent);
}

Is it something here that's causing the error? It looks like the file is somehow not being stored in the filesystem when the app is installed.

1 Answers1

0

Just like @ruben said, you could use a WebView for such a task: https://developer.android.com/reference/android/webkit/WebView. For more information about using WebView to display content, you can take a look at this post: How can I display a pdf document into a Webview?

Another potential solution could be using intents, which has also been discussed before: How to open a PDF via Intent from SD card

Hopefully this helps!

AvidRP
  • 373
  • 2
  • 11
  • I looked at the article on using intents that you offered, and have made significant progress. Now, the issue is, the pdf viewer opens, but the PDF does not display... – WhispTheFox Dec 05 '18 at 03:04