首页 > 解决方案 > 如何使用较低 API 的 java.nio 中的 toAbsolutePath 和 Paths.get

问题描述

我有一个应用程序需要在电子邮件中发送多个图像附件。要发送图像,我需要一个绝对路径。为此,我使用函数.toAbsolutePathPaths.getfrom java.nio。这两个功能仅适用于API 26或更高版本。在我看来,它们就像是非常基本的功能,所以我不知道为什么它们不支持较低的 API。有什么方法可以让他们使用 lowerAPIs吗?

realPath1 = Paths.get("storage/emulated/0/Android/data/com.example.abbmalfunctionreport/cache/$image1").toAbsolutePath()

标签: androidfilekotlinpathandroid-api-levels

解决方案


File.getAbsolutePath()从 API-1 开始可用。

您可能还应该使用Environment类,请参阅如何在 Android 中获取内部存储的绝对路径


推荐阅读