为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 329 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号