简体   繁体   English

从外部存储打开文件

[英]open file from external storage

I am trying to use intent for open files in external storage but I don't know why is it showing me toast could not find item !我正在尝试使用 Intent 来打开外部存储中的文件,但我不知道为什么它会显示 toast could not find item ! I have tried it on different files as well but it do the same , permissions I have used in manifest我也在不同的文件上尝试过,但它的作用相同,我在清单中使用的权限

 @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());

    }

}

can you show sample address value (path of the file)?你能显示示例address值(文件路径)吗? there is a chance that you are keeping your files in some restricted area (eg private data folder of your app) and you have to provide FileProvider and grant Uri access permission to another app for allowing it to use your apps folder.有可能您将文件保存在某个受限区域(例如应用程序的私有数据文件夹),并且您必须提供FileProvider并授予另一个应用程序的Uri访问权限,以允许它使用您的应用程序文件夹。 some doc and samples in HERE and HERE 这里这里的一些文档和示例

assuming could not find item !假设could not find item ! Toast doesn't come from your app (I don't see such code) - it may be shown by another app, which just can't get access to File Toast不是来自您的应用程序(我没有看到此类代码)-它可能由另一个应用程序显示,而该应用程序无法访问File

all above assumes that File exists in proper directory (both isFile() and exists() returns true ) :)以上都假设File存在于正确的目录中( isFile()exists()返回true ):)

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

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