0

When I click the Button it open the link and ask me what program I want to open pdf. Then it pop's up a message box and says file has (0 byte) cant open.

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

    public void browser1(View view){
        Intent BrowserIntent=new Intent(Intent.ACTION_VIEW,
            Uri.parse("http://www.docdroid.net/file/download/mUaJciS/contatos-lubrifuel.pdf"));
        startActivity(BrowserIntent);
    }    
}
slinden77
  • 3,378
  • 2
  • 37
  • 35
  • 2
    Download the file, first, then use ACTION_VIEW to open it locally. –  Jun 13 '16 at 13:10
  • 1
    this will help to download the file http://stackoverflow.com/questions/3028306/download-a-file-with-android-and-showing-the-progress-in-a-progressdialog – johnrao07 Jun 13 '16 at 13:11

1 Answers1

0

First check if your PDF is accessible. Check this discussion: Android Intent.ACTION_VIEW

Or do this: Pass the URL parameter as extra to your WebView Activity:

public void browser1(View view){

  Intent BrowserIntent=new Intent(Intent.ACTION_VIEW);
  String PDFurl = "http://www.docdroid.net/file/download/mUaJciS/contatos-lubrifuel.pdf";
  BrowserIntent.putExtra("PDFUrl", PDFurl);
  startActivity(BrowserIntent);
}

Then in your started activity call (into the onCreate method)

WebView webview = (WebView) findViewById(R.id.your_webview);
String PDFurl = getIntent().getExtras().getString("PDFUrl");
webview.getSettings().setJavaScriptEnabled(true); 
webview.loadUrl(PDFurl);
Community
  • 1
  • 1
rik194
  • 118
  • 1
  • 12