0

下载完成后自动崩溃。。

f (file.isFile()) {
        Intent mIntent = new Intent(SingleItemView.this,
                PdfViewerClass.class);
        mIntent.putExtra(PdfViewerActivity.EXTRA_PDFFILENAME,
                file.getAbsolutePath());
        startActivity(mIntent);
        finish();
    } else {
        downloadFile();
    }

05-21 16:26:03.138: E/WindowManager(14556): Activity com.example.pdfview.SingleItemView       has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4197ab30 V.E..... R.....ID 0,0-465,326} that was originally added here
05-21 16:26:03.138: E/WindowManager(14556): android.view.WindowLeaked: Activity  com.example.pdfview.SingleItemView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{4197ab30 V.E..... R.....ID 0,0-  465,326} that was originally added here
05-21 16:26:03.138: E/WindowManager(14556):     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:409)
05-21 16:26:03.138: E/WindowManager(14556):     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:218)
05-21 16:26:03.138: E/WindowManager(14556):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)

以上错误是在运行时检测到的,请给我解决方案。

4

1 回答 1

1

尝试这个,

File pdfFile = new File(Environment

  .getExternalStorageDirectory(), "your.pdf");


try {

 if (pdfFile.exists()) {

  Uri path = Uri.fromFile(pdfFile);

  Intent objIntent = new Intent(Intent.ACTION_VIEW);

  objIntent.setDataAndType(path, "application/pdf");

  objIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

  startActivity(objIntent);

 } else {

  Toast.makeText(MainActivity.this, "File NotFound",

    Toast.LENGTH_SHORT).show();

 }

} catch (ActivityNotFoundException e) {

 Toast.makeText(MainActivity.this,

   "No Viewer Application Found", Toast.LENGTH_SHORT)

  .show();

} catch (Exception e) {

 e.printStackTrace();

}
于 2014-05-21T11:05:40.507 回答