小编Com*_*dge的帖子

从资产或res/raw中获取Uri文件

我试图让这个工作,我已经在线查看了许多不同的资源(你可以从我所做的所有评论中看到).我想访问位于资产或资源中的.pdf文件; 这对最简单的方法来说无关紧要.

我有下面的方法将获得实际文件,并将参数中的Uri调用另一个方法(在下面的第一个方法下).

非常感谢您的帮助,我将随时回答问题或添加更多内容.

private void showDocument(File file)
{
    //////////// ORIGINAL ////////////////////
    //showDocument(Uri.fromFile(file));
    //////////////////////////////////////////

    // try 1
    //File file = new File("file:///android_asset/RELATIVEPATH");

    // try 2
    //Resources resources = this.getResources();

    // try 4
    String PLACEHOLDER= "file:///android_asset/example.pdf";
    File f = new File(PLACEHOLDER);

    //File f = new File("android.resource://res/raw/slides1/example.pdf");

    //getResources().openRawResource(R.raw.example);

    // try 3
    //Resources resources = this.getResources();
    //showDocument(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + resources.getResourcePackageName(R.raw.example) + '/' + resources.getResourceTypeName(R.raw.example) + '/' + resources.getResourceEntryName(R.raw.example)));

    showDocument(Uri.fromFile(f));
}

protected abstract void showDocument(Uri uri);
Run Code Online (Sandbox Code Playgroud)

java pdf android uri android-resources

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

标签 统计

android ×1

android-resources ×1

java ×1

pdf ×1

uri ×1