如何在Android上使用Intent打开Firefox about:reader?url = example.com

时间:2018-07-31 14:36:51

标签: android android-intent uri

我正在尝试在android应用程序上打开网页,但网址sheme有点特殊,它必须以阅读器模式打开网址: about:reader?url=example.com

我正在这样做

Uri intentUri = new Uri.Builder().encodedPath("about:reader")
    .appendQueryParameter("url", Uri.encode("example.com"))
    .build();

// Try to open in Firefox If available or use default
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(intentUri);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("org.mozilla.firefox");

try {
    getApplicationContext().startActivity(intent);
} catch (ActivityNotFoundException ex) {
    intent.setPackage(null);
    getApplicationContext().startActivity(intent);
}

Logcat:

E/AndroidRuntime: FATAL EXCEPTION: main Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=about:reader?url=http://example.com

有没有办法做到这一点?

1 个答案:

答案 0 :(得分:-1)

尝试一下

final String pdf_url = "http://example.com"; // DON'T forget http{s}:// prefix.
// Try to open in Firefox If available or use default
Intent intent=new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(pdf_url));
// You can also using Google viewer 
// intent.setDataAndType(Uri.parse( "http://docs.google.com/viewer?url=" + pdf_url), "text/html");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setPackage("org.mozilla.firefox");