Android 从uri中获取路径

  public static String getPathFromUri(Context context, Uri uri) {
    try (Cursor cursor = context.getContentResolver()
        .query(uri, new String[]{Media.DATA}, null, null, null)) {
      if (cursor != null && cursor.moveToFirst()) {
        int index = cursor.getColumnIndex(Media.DATA);
        return cursor.getString(index);
      } else {
        return "";
      }
    }
  }

你可能感兴趣的:(android,android)