从 URL 打开 PDF

发布于 2024-12-08 23:17:13 字数 2419 浏览 1 评论 0原文

我是android开发的新手。我必须显示来自 URL 的 PDF。

这是我当前的代码,但我无法显示 PDF 文件:

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)

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灵芸 2024-12-15 23:17:13

它在这里工作得很好。还是建议您测试一下您是否在 AndroidManifest.xml 文件中添加了 INTERNET 权限:

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

更新:

您要打开的链接是: http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf

现在它在这里也工作正常:

在此处输入图像描述

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文