如何在android模拟器中显示pdf

时间:2011-09-28 07:49:05

标签: android

我想在模拟器中显示pdf。我使用以下代码。

public class PdfActivity extends Activity 
{

public void onCreate(Bundle savedInstanceState) 
{
    URL url;
    Button btn;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


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

    btn=(Button)findViewById(R.id.press);

    try
    {
      //url=new URL("http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf");



    }catch(Exception e)
    {
        e.printStackTrace();
    }

    btn.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) 
        {
            Uri uri = Uri.parse("http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf");
             Intent intent = new Intent(Intent.ACTION_VIEW, uri);
             startActivity(intent);

        }
    });

}
}

但它告诉我错误是我的logcat -

09-28 13:16:24.697: ERROR/WindowManager(283): Activity com.android.browser.BrowserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f601d8 that was originally added here
09-28 13:16:24.697: ERROR/WindowManager(283): android.view.WindowLeaked: Activity com.android.browser.BrowserActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44f601d8 that was originally added here
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.view.ViewRoot.<init>(ViewRoot.java:247)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.view.Window$LocalWindowManager.addView(Window.java:424)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.app.Dialog.show(Dialog.java:241)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.app.AlertDialog$Builder.show(AlertDialog.java:802)
09-28 13:16:24.697: ERROR/WindowManager(283):     at com.android.browser.BrowserActivity.onDownloadStartNoStream(BrowserActivity.java:2871)
09-28 13:16:24.697: ERROR/WindowManager(283):     at com.android.browser.BrowserActivity.onDownloadStart(BrowserActivity.java:2808)
09-28 13:16:24.697: ERROR/WindowManager(283):     at com.android.browser.Tab$4.onDownloadStart(Tab.java:1306)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:387)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.os.Looper.loop(Looper.java:123)
09-28 13:16:24.697: ERROR/WindowManager(283):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-28 13:16:24.697: ERROR/WindowManager(283):     at java.lang.reflect.Method.invokeNative(Native Method)
09-28 13:16:24.697: ERROR/WindowManager(283):     at java.lang.reflect.Method.invoke(Method.java:521)
09-28 13:16:24.697: ERROR/WindowManager(283):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-28 13:16:24.697: ERROR/WindowManager(283):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-28 13:16:24.697: ERROR/WindowManager(283):     at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:0)

没有简单的方法可以做到:

Render a PDF file using Java on Android

答案 1 :(得分:0)

您想要打开此位置上显示的pdf http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf 所以基本上你想要显示一个html页面,所以使用webview。

答案 2 :(得分:0)

如果你想在Android应用程序中打开pdf,请尝试使用谷歌文档 -

   String pdfurl = "http://www.example.com/yourfile.pdf";
   String googleDocsUrl = "http://docs.google.com/viewer?url="+pdfurl;
   Intent intent = new Intent(Intent.ACTION_VIEW);
   intent.setDataAndType(Uri.parse(googleDocsUrl ), "text/html");