Android-从内存中选择文件

时间:2018-11-01 15:58:16

标签: java android android-intent

我想从内存中选取文件,但是出现错误:“没有这样的文件或目录” 。 我不知道该怎么办,因为文件路径不是“ storage /...",而是” / document / raw:/ storage /..."。仅仅替换“ / document / raw:”是不好的,因为在另一台设备上文件路径是” / external_files / Download /...”

打开文件方法:

public void openFile(String minmeType, int requestCode) {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType(minmeType);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        startActivityForResult(intent, requestCode);
    }

onActivityResult:

@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (data != null){
            if (requestCode == 228){
                File current = new File(data.getData().getPath());

                File theme = new File(android.os.Environment.getExternalStorageDirectory().getAbsolutePath() + "/Made by F0x1d/" + "/theme");

         ...
        super.onActivityResult(requestCode, resultCode, data);
    }

0 个答案:

没有答案