2

I made a lot of searching before asking here.

I cant open a pdf in my Webview , i had the following error : No Activity found to handle Intent error.

Here is the code of the WebBrowser activity :

webview.setWebChromeClient(new WebChromeClient() {

public void onProgressChanged(WebView view, int progress) {
   activity.setProgress(progress * 100);
     }
     });

 webview.setWebViewClient(new WebViewClient() {
   public boolean shouldOverrideUrlLoading(WebView view, String url) {
          if (url.endsWith("pdf")) {

      Intent intentUrl = new Intent(android.content.Intent.ACTION_VIEW);
          intentUrl.setDataAndType(Uri.parse(url),MIME_TYPE_PDF); 
         startActivity(intentUrl);

        }
                  else{
              view.loadUrl(url);
          }
              return true;
          }

public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
     //Users will be notified in case there's an error (i.e. no internet connection)
     Toast.makeText(activity, "Oops! Connexion inexistante ou " + description, Toast.LENGTH_SHORT).show();
                }
     });  

  //This will load the webpage that we want to see
  webview.setPictureListener(this);
  webview.loadUrl(WebAddress);  
}

Here is the manifest xml :

    <application android:icon="@drawable/icon" android:label="@string/VisitEnsta">
     <activity android:name=".SplashScreen" 
              android:label="@string/app_name">
            <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                 <action android:name="android.intent.action.VIEW" />
                 <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
     </activity>

     <activity android:name=".main"
           android:configChanges="locale"></activity>

     <activity android:name=".Apropos"></activity>

    <activity android:name=".Resultat"
          android:configChanges="locale"></activity>

    <activity android:name=".SyntheseVocale" 
          android:configChanges="locale"></activity>

    <activity android:name=".Visite"
          android:configChanges="locale"></activity>

    <activity android:name=".RssActivity" android:theme="@style/ListTheme"></activity>

    <activity android:name=".WebBrowser">
        <intent-filter>
         <action android:name="android.intent.action.VIEW" />

        </intent-filter>
    </activity>

    <activity android:name=".Utilities">
    <intent-filter>
         <action android:name="android.intent.action.VIEW" />

        </intent-filter>
    </activity>

    <activity android:name=".StudentsAccess">
    <intent-filter>
         <action android:name="android.intent.action.VIEW" />

        </intent-filter>
    </activity>



</application>
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.CAMERA"/>


</manifest> 

I have adobe reader installed on my phone, and i debug on a real device (Galaxy S).

Her is the error trace :

06-12 20:13:10.312: E/AndroidRuntime(3311): android.content.ActivityNotFoundException:               No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://www.ensta-bretagne.fr/images/contenu//EspaceDocumentation/depliant_institutionnelle_fr_novembre2011_web.pdf typ=application/pdf }

Please have you any solution ?

SolidSnake87
  • 343
  • 3
  • 12
  • See my answer **[here](http://stackoverflow.com/a/14151204/1931228)**. My solution discourages the use of setDataAndType as it doesn't seem to work with PDF types via online link. – Pier Betos Jan 04 '13 at 04:49

2 Answers2

2

Here is the code which i have used to view the pdf file in webview. Please check it .

WebView webview=new WebView(SpecialityAllManuals.this);
                        webview.getSettings().setJavaScriptEnabled(true); 
                        String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";

                        webview.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
itsrajesh4uguys
  • 4,610
  • 3
  • 20
  • 31
  • 1
    Thanx, it has been a while since i dropped the idea of showing .pdf in webview, but i think your contribution will help many programmers in this case. – SolidSnake87 Feb 20 '13 at 14:56
  • what if the pdf is stored locally and no internet @itsrajesh4ugys? – gumuruh Mar 13 '22 at 19:05
0

Use Adobe Reader (or another installed pdf viewer) via an intent. See this solution on SO here

Community
  • 1
  • 1
JWL
  • 13,591
  • 7
  • 57
  • 63