gpt4 book ai didi

android - 在应用程序中打开 Assets 文件 pdf

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:19:41 27 4
gpt4 key购买 nike

我已经搜索过,但没有找到任何在应用程序中显示 pdf 文件的解决方案

关键是我必须显示来自 Assets 或原始文件夹的 pdf 而不是来自网络

我已经在 webview 中用代码试过了

    WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.setContentDescription("application/pdf");
webview.loadUrl("file:///android_asset/button11.pdf");

但它没有醒来。

我需要帮助提前致谢

最佳答案

这是我用来从文件系统读取 pdf 的代码,希望对您有所帮助!

        File file = new File("/path/to/file");          
Uri path = Uri.fromFile(file);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

try {
context.startActivity(intent);
}
catch (ActivityNotFoundException e) {
Toast.makeText(context, "No application available to view PDF", Toast.LENGTH_LONG).show();
}

关于android - 在应用程序中打开 Assets 文件 pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743807/

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