Using the FileOpener plugin to open the GPX file after export (#9).

This commit is contained in:
vdv committed 2022-10-02 17:16:41 +02:00
1 parent ca28d767c0
commit 0b96918f3d
3 files changed
+28 -1

No files matched your search

+8 -1
View File
@@ -3,6 +3,7 @@ import { cloudDownload } from 'ionicons/icons';
import React, { Fragment, useRef } from 'react';
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
import { useDB } from 'react-pouchdb';
import { FileOpener } from '@capacitor-community/file-opener';
import { getGpxAsXmlString } from '../../db/gpx';
const GpxExport: React.FC<{ gpx: any }> = (props: { gpx: any }) => {
@@ -29,13 +30,19 @@ const GpxExport: React.FC<{ gpx: any }> = (props: { gpx: any }) => {
const gpxAsXml = await getGpxAsXmlString(db, props.gpx._id);
console.log(`gpxAsXml: ${gpxAsXml}`);
if (isCapacitor) {
await Filesystem.writeFile({
const fileUrl = await Filesystem.writeFile({
path: `Download/${downloadName}`,
data: gpxAsXml,
directory: Directory.Documents,
encoding: Encoding.UTF8,
recursive: true,
});
console.log(`fileUrl: ${fileUrl.uri}`);
await FileOpener.open({
filePath: fileUrl.uri,
contentType: 'application/gpx+xml',
openWithDefault: false,
});
} else {
const blob = new Blob([gpxAsXml], {
type: 'application/gpx+xml',