亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

android pie:我無法獲取文件名或文件路徑

android pie:我無法獲取文件名或文件路徑

斯蒂芬大帝 2022-05-21 20:37:18
我的代碼在任何設備上都可以正常工作..但不能在 android pie 上工作我正在嘗試從片段中的 onActivityResult 獲取真實路徑和文件名我正在使用 apachi 庫中的 FileNameUtils并使用這個庫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();////      }    }  }更新..在下一個..修復它第一的獲取文件名我用過這個功能  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();    }  }
查看完整描述

1 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

看這個 。安卓參考


查看完整回答
反對 回復 2022-05-21
  • 1 回答
  • 0 關注
  • 264 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號