相关疑难解决方法(0)

从assets文件夹中读取pdf文件

public void DOCS(View btnDocs)
{   
    File fileBrochure = new File("android.resource://com.project.datastructure/assets/abc.pdf");
    if (!fileBrochure.exists())
    {
         CopyAssetsbrochure();
    } 

    /** PDF reader code */
    File file = new File("android.resource://com.project.datastructure/assets/abc.pdf");        

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.fromFile(file),"application/pdf");
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    try 
    {
        getApplicationContext().startActivity(intent);
    } 
    catch (ActivityNotFoundException e) 
    {
         Toast.makeText(Stack_dr.this, "NO Pdf Viewer", Toast.LENGTH_SHORT).show();
    }
}
private void CopyAssetsbrochure() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try 
    {
        files = assetManager.list("");
    } 
    catch (IOException e){}
    for(int i=0; i<files.length; i++)
    {
        String fStr = files[i];
        if(fStr.equalsIgnoreCase("abc.pdf"))
        { …
Run Code Online (Sandbox Code Playgroud)

java android android-intent

24
推荐指数
3
解决办法
5万
查看次数

如何打开存储在res/raw或assets文件夹中的pdf?

我将在我的应用程序中显示pdf,并且pdf必须与应用程序捆绑在一起.

有什么好办法呢?

我已经读过,可以通过将pdf文件添加到res/raw文件夹并从那里读取它来实现这一点,但是当我将pdf文件放在那里时我得到了项目错误.

所以我试着把pdf文件放在项目的资产文件夹中,它没有给出任何错误.

这是我试图显示pdf的方式:

File pdfFile = new File("res/raw/file.pdf");
Uri path = Uri.fromFile(pdfFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(path, "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Run Code Online (Sandbox Code Playgroud)

任何想法或建议?

提前致谢

pdf android assets file

23
推荐指数
2
解决办法
5万
查看次数

标签 统计

android ×2

android-intent ×1

assets ×1

file ×1

java ×1

pdf ×1