gpt4 book ai didi

android - 如何在 Android 上使用 Intent 打开关于 :reader? url=example.com 的 Firefox

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:17:33 26 4
gpt4 key购买 nike

我试图在 android 应用程序上打开一个网页,url sheme 有点特殊,它必须在阅读器模式下打开一个 url: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);
}

日志:

E/AndroidRuntime: 致命异常: main
由以下原因引起:android.content.ActivityNotFoundException:找不到处理 Intent 的 Activity { act=android.intent.action.VIEW dat=about:reader?url=http://example.com

有办法实现吗?

最佳答案

试试这个

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

关于android - 如何在 Android 上使用 Intent 打开关于 :reader? url=example.com 的 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51615968/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com