• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps PDFs don't show up in test device

StevenHu

Member
I have an HTML page that links to several editable PDFs. By right-clicking on the index.html page in Eclipse and choosing Web Browser for the viewing mode, I can see the html page, click on a link, and the PDF appears. I can even click on a field and enter information. So the html page is correct.

But when I test on an Android device, clicking on a link does not bring up any PDF, even though the html page appears just fine. Is there a special way to show a PDF on the screen? In my case, the PDF is part of the app, and I link to it in the html page with a simple <a href=> tag.

There are no error or warning messages in the console.

(I had created another Android app and it works just fine in the test device.)

Any ideas for me to try to get the PDFs to appear?

Thanks,
Steve
 
Other PDFs show up fine on the device. This was tested in 2 devices, both of which displayed PDFs apart from this app.

I had started with a default Hello World and changed it. I looked at res/layout for the first time and see:

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>

This is probably the reason the PDFs are not showing up in the device. I probably have to make that a WebView. Any clues?
 
Code:
private void openBook() {         
 File file = new File(mRealPath);         
 Uri path = Uri.fromFile(file);         
 Intent intent = new Intent(Intent.ACTION_VIEW);    
 intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);         
 intent.setDataAndType(path, getString(R.string.application_type));         
 try  {             
  startActivity(intent);         
 }          
 catch (ActivityNotFoundException e) {             
  Toast.makeText(FirstTab.this,                  
  getString(R.string.no_application_found),                  
  Toast.LENGTH_SHORT).show();         
 }     
}

something like this to open the pdf?
 
I used your code in my main.xml like this:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<WebView android:id="@+id/web_engine"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

private void openBook() {
File file = new File(mRealPath);
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(path, getString(R.string.application_type));
try {
startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(FirstTab.this,
getString(R.string.no_application_found),
Toast.LENGTH_SHORT).show();
}
}

</LinearLayout>

It still did not open the link. Is there another page I am supposed to change?

The files I am trying to open contain editable fields. I have one PDF that, when its link is clicked on, does not show the actual PDF, but a long series of characters.
 
It looks like Android does not have native PDF viewing. Does anyone have any working code to share on how they managed to view PDFs from within the app?
 
Code inside the layout xml file? What the Who? Did I miss out in something there or is that just wrong?

And, as I tried to say a little unclear in #2, Android does not have a build in program for PDF viewing, it has to be installed by the user, manufacturer or carrier. And that is why you shoulf use that intent mentioned in #5, as it will send a message to the system to show any available apps to handle the PDF file...

But maybe you need to get pietjuhhh to tell what his R.string.application_type returns, so you'll know what to put in there...
 
JamTheMan, I'm new enough at this that it was probably wrong! :) If the code in #5 did not belong in the main.xml file, where did it belong?
 
It belongs in the Activity that holds the links to the PDF's, and when a PDF is pressed, you should call the openBook method...
 
So this code will open PDFs containing text fields to be filled in and saved with the field contents?

All I know is HTML, CSS, and a hint of JS. I don't know Java, sorry.
 
Yeah... IF the device has an app that can handle PDF's, it should give the user a list of of usable apps to open it with, and then open it in that app. What the selected app does/can do with it, is out of your hands, unless you make it yourself...
 
Back
Top Bottom