0

I made an android application. I created a extensible list, when I click on a child I want to be open a PDF. The PDF is not open, is displayed a message that is content from no_application_found ("The PDF can not be open"). The code for open PDF is:

    public boolean onChildClick (
        ExpandableListView parent, 
        View v, 
        int groupPosition,
        int childPosition,
        long id) {
    Log.d( LOG_TAG, "onChildClick: " + childPosition );

    File file = new File("http://www.ratt.ro/grafice/e2-a.pdf");
    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(ElistCBox.this, 
            getString(R.string.no_application_found), 
            Toast.LENGTH_SHORT).show();
    }

    return false;
}
Andreea
  • 151
  • 1
  • 3
  • 12

2 Answers2

3

This is how you open a PDF in a web-View:

webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.ratt.ro/grafice/e2-a.pdf");
PrincessLeiha
  • 3,144
  • 4
  • 32
  • 53
1

Here is my code for opening PDF file in reader, if user do not have any pdf reader it opens link to Google play for downloading one:

void openpdf (String filename)

{
    String loc = "/sdcard/";
    File file = new File(loc+filename);
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(path, "application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    try {
        startActivity(intent);
    } catch (Exception e) {

        e.printStackTrace();
        Toast.makeText(getApplicationContext(), "No pdf reader installed", Toast.LENGTH_SHORT).show();
        Intent market = new Intent(Intent.ACTION_VIEW);
        market.setData(Uri.parse("market://details?id=com.adobe.reader"));
        startActivity(market);
    }

}
DanM
  • 1,530
  • 4
  • 23
  • 44