android - Showing cannot open file -


this code download , open file sdcard.

but after downloading file, when click on file open it, shows toast message: cannot open file

please tell me error.

package com.pdf;  import java.io.file; import android.app.activity; import android.content.activitynotfoundexception; import android.content.intent; import android.net.uri; import android.os.bundle; import android.webkit.webview; import android.widget.toast;  public class pdffileactivity extends activity  {    webview webview;      @override     public void oncreate(bundle savedinstancestate)     {        super.oncreate(savedinstancestate);        setcontentview(r.layout.main);       webview = (webview) findviewbyid(r.id.webview);        string pdf = "http://officeofthemufti.sg/maulidbooklet.pdf";       webview.loadurl("http://docs.google.com/gview?embedded=true&url=" + pdf);       setcontentview(webview);        file file=new file("/sdcard/maulidbooklet.pdf");        if (file.exists())       {          uri path = uri.fromfile(file);          intent intent = new intent(intent.action_view);          intent.setdataandtype(path, "application/pdf");          intent.setflags(intent.flag_activity_clear_top);          startactivity(intent);          try         {            startactivity(intent);         }         catch (activitynotfoundexception e)         {            toast.maketext(pdffileactivity.this,                           "no application available view pdf",                           toast.length_short).show();         }     } } 

if want open programatically say, , assuming has been downloaded standard 'download' directory can change declaration , instantiation of new file following:

file file = new file(environment.getexternalstoragepublicdirectory(environment.directory_downloads)  + "/maulidbooklet.pdf"); 

this assume using android 2.2 or newer.

you can check file being downloaded directory using ddms browse 'download' directory on device.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -