0

我想在 pdfviewer 中从 URL 打开 pdf

我尝试下面的代码。它打开 pdfviewer 但最近的文档没有我的 URL 吗?

如何直接在pdfviewer中打开文件?

Intent intent = new Intent(Intent.ACTION_VIEW,
                Uri.parse("http://inventwithpython.com/hackingciphers.pdf"));
        intent.setType("application/pdf");
        PackageManager pm = getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
        if (activities.size() > 0) {
            startActivity(intent);
        } else {
            // Do something else here. Maybe pop up a Dialog or Toast
            Toast.makeText(getApplicationContext(),"No pdf found" , Toast.LENGTH_LONG).show();
            final String appName = "com.adobe.reader";
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id="+appName)));
            } catch (android.content.ActivityNotFoundException anfe) {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id="+appName)));
            }

        }
4

1 回答 1

1

试试这个代码

Uri uri = Uri.parse("http://inventwithpython.com/hackingciphers.pdf");

        Intent pdfOpenintent = new Intent(Intent.ACTION_VIEW,uri);
        pdfOpenintent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        pdfOpenintent.setDataAndType(uri, "application/pdf"); // )

        try {
            startActivity(pdfOpenintent);
        } catch (ActivityNotFoundException e) {

        }
于 2013-09-27T06:51:56.887 回答