繁体   English   中英

从外部存储打开文件

[英]open file from external storage

我正在尝试使用 Intent 来打开外部存储中的文件,但我不知道为什么它会显示 toast could not find item ! 我也在不同的文件上尝试过,但它的作用相同,我在清单中使用的权限

 @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

     File temp = new File(address,mylist.get(position));

    if (temp.isFile()){
        //Toast.makeText(getApplicationContext(),"This is File !!",Toast.LENGTH_SHORT).show();
        String  sfile = temp.getPath();
        Uri uri = Uri.parse(sfile);
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setType("image/*");
        intent.putExtra(Intent.ACTION_VIEW,uri);
        
        startActivity(Intent.createChooser(intent,"Open file"));

    }else {

        ref(address+"/"+mylist.get(position).toString());

    }

}

你能显示示例address值(文件路径)吗? 有可能您将文件保存在某个受限区域(例如应用程序的私有数据文件夹),并且您必须提供FileProvider并授予另一个应用程序的Uri访问权限,以允许它使用您的应用程序文件夹。 这里这里的一些文档和示例

假设could not find item ! Toast不是来自您的应用程序(我没有看到此类代码)-它可能由另一个应用程序显示,而该应用程序无法访问File

以上都假设File存在于正确的目录中( isFile()exists()返回true ):)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM