From e687e9d75650a1fc875d31fa30e4f43455e7c197 Mon Sep 17 00:00:00 2001 From: farfromrefuge Date: Sat, 12 Nov 2022 18:07:50 +0000 Subject: [PATCH] fix(android): normalize for API >= 26 (#10083) --- .../file-system/file-system-access.android.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/core/file-system/file-system-access.android.ts b/packages/core/file-system/file-system-access.android.ts index 68c43b05c..cbcea607e 100644 --- a/packages/core/file-system/file-system-access.android.ts +++ b/packages/core/file-system/file-system-access.android.ts @@ -1,5 +1,9 @@ import * as textModule from '../text'; import { getNativeApplication } from '../application'; +import { Device } from '../../platform'; +import lazy from '../../utils/lazy'; + +const sdkVersion = lazy(() => parseInt(Device.sdkVersion)); import type { IFileSystemAccess } from './file-system-access'; @@ -581,9 +585,15 @@ export class FileSystemAccess implements IFileSystemAccess { } public normalizePath(path: string): string { - // the [''] is a trick to not have to create a android.net.URI - // and use the method with string signature - return java.nio.file.Paths.get(path, ['']).normalize().toString(); + if (sdkVersion() >= 26) { + // the [''] is a trick to not have to create a android.net.URI + // and use the method with string signature + return java.nio.file.Paths.get(path, ['']).normalize().toString(); + } else { + // for now it wont work on pre 26 as File does not normalize + const file = new java.io.File(path); + return file.getAbsolutePath(); + } } public joinPath(left: string, right: string): string {