3

I am a novice at android development. I have to show a PDF from a URL.

This is my current code but I'm not able to show the PDF file:

public class TestActivity extends Activity 
{

    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        System.setProperty("http.proxyHost","192.168.0.2");
        System.setProperty("http.proxyPort","8080");

        showPdf();
    }    

    private void showPdf() 
    {
        WebView webview = new WebView(this); 
        setContentView(webview); 
        webview.getSettings().setJavaScriptEnabled(true); 
        Log.v("....hello....","");
        webview.loadUrl("http://docs.google.com/gview?embedded=true&url=http://myurl.com/demo.pdf");

    }

}

Logcat:

10-11 14:50:49.586: ERROR/AndroidRuntime(537): FATAL EXCEPTION: main
10-11 14:50:49.586: ERROR/AndroidRuntime(537): android.app.SuperNotCalledException: Activity {com.vidushi.Test/com.vidushi.Test.TestActivity} did not call through to super.onCreate()
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2629)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.os.Looper.loop(Looper.java:123)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at android.app.ActivityThread.main(ActivityThread.java:4627)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at java.lang.reflect.Method.invokeNative(Native Method)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at java.lang.reflect.Method.invoke(Method.java:521)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-11 14:50:49.586: ERROR/AndroidRuntime(537):     at dalvik.system.NativeStart.main(Native Method)
Rais Alam
  • 6,970
  • 12
  • 53
  • 84
user988853
  • 59
  • 1
  • 1
  • 5

1 Answers1

1

Its working fine here. Still let me suggest you to test whether you have added INTERNET permission in AndroidManifest.xml file or not:

<uses-permission android:name="android.permission.INTERNET"></uses-permission>

Update:

The link you want to open is: http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf

Now its also working fine here:

enter image description here

Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
  • @user988853 Just give one hand on project->clean. – Paresh Mayani Oct 11 '11 at 10:38
  • yes paresh i deleted because every time it show me chating option.is it possible to show pdf file in android emulator or you use pdf viewer for screen shot?i use all option.my emulator browser show google.com but when i do this programming it is not working it show me-"the web page might be temporarily down or it may have moved permanently to a new web address". – user988853 Oct 11 '11 at 13:50
  • @user988853 I have taken snap from real device after running your code. – Paresh Mayani Oct 11 '11 at 13:51
  • oh i confused,i think you are talking about emulator.so it is not possible to show without any pdf viewer?because iPhone we can do this. – user988853 Oct 11 '11 at 13:55
  • @user988853 For your information, you have taken WebView to load PDF, so for this there is no any requirement of PDF viewer. – Paresh Mayani Oct 11 '11 at 13:56
  • (1)i change proxy and port setting in emulator as well as from coding.(2)i write internet permission(3)copy-paste from google docs but it is not working – user988853 Oct 11 '11 at 14:04