简体   繁体   中英

how to show pdf in android emulator

i want to show pdf in emulator.the following code i use.

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);

        }
    });

}
}

But it show me errors that is my 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)

There is no easy way to do it:

Render a PDF file using Java on Android

您想打开一个在该位置存在的pdf文件http://litofinter.es.milfoil.arvixe.com/PDF/Book6.pdf因此,基本上,您想显示一个html页面,因此请使用webview。

If you want to open pdf in android app try using google docs-

   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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM