簡體   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