我的代碼在任何設(shè)備上都可以正常工作..但不能在 android pie 上工作我正在嘗試從片段中的 onActivityResult 獲取真實(shí)路徑和文件名我正在使用 apachi 庫(kù)中的 FileNameUtils并使用這個(gè)庫(kù)https://gist.github.com/tatocaster/32aad15f6e0c50311626但它給了我空這是我的代碼private void pickFile() { Intent intent = new Intent(); intent.setType("*/*"); intent.setAction(Intent.ACTION_GET_CONTENT); startActivityForResult(Intent.createChooser(intent, "Select File"), PICKFILE_REQUEST_CODE); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == PICKFILE_REQUEST_CODE) { filePath = RealPathUtil.getRealPath(getContext(), data.getData()); fileName = FilenameUtils.getName(filePath); Log.i("FileNameIs",filePath + "Hello " + fileName );// if (fileName !=null)// {// mFileName// .setText(fileName.isEmpty() ? getString(R.string.failed_please_try_again) : fileName);//// deleteOldPath();//// } } }更新..在下一個(gè)..修復(fù)它第一的獲取文件名我用過這個(gè)功能 public void dumpImageMetaData(Uri uri) { String TAG = "TagIs"; // The query, since it only applies to a single document, will only return // one row. There's no need to filter, sort, or select fields, since we want // all fields for one document. Cursor cursor = getActivity().getContentResolver() .query(uri, null, null, null, null, null); try { // moveToFirst() returns false if the cursor has 0 rows. Very handy for // "if there's anything to look at, look at it" conditionals. if (cursor != null && cursor.moveToFirst()) { // Note it's called "Display Name". This is // provider-specific, and might not necessarily be the file name. String displayName = cursor.getString( cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME)); fileName = displayName ==null ? "Failed" : displayName; deleteOldPath(); } } finally { cursor.close(); } }
添加回答
舉報(bào)
0/150
提交
取消