Android - How do I open a file in another app via Intent?

后端 未结 2 1730
礼貌的吻别
礼貌的吻别 2021-02-15 07:42

I\'m trying to open a file using another app, i.e. opening a .jpg with Gallery, .pdf with Acrobat, etc.

The problem I\'m having with this is when I try to open the file

2条回答
  •  野的像风
    2021-02-15 08:35

    I used this piece of code and it worked perfectly fine on android 6 and below not tested on the higher version

    public void openFile(final String fileName){
        Intent intent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.fromFile(new File(android.os.Environment.getExternalStorageDirectory()
                .getAbsolutePath()+ File.separator+"/Folder/"+fileName));
        intent.setDataAndType(uri, "audio/mpeg");
        startActivity(intent);
    }
    

提交回复
热议问题