File and Geolocation

cordova-plugin-file and cordova-plugin-geolocation

cordova-plugin-file (8.1.3) implements an old W3C draft, the File and Directory Entries API, on top of native storage. cordova.file.dataDirectory is the app's private files folder, which the system deletes with the app and includes in backups unless allowBackup is off (edit-config). The API is callback-based, so one helper turns each call into a Promise:

Saving and reading back a reading note with cordova-plugin-fileJavaScript
const call = (fn, ...args) => new Promise((resolve, reject) => fn(...args, resolve, reject));
const dir = await call(resolveLocalFileSystemURL, cordova.file.dataDirectory);
const entry = await call(dir.getFile.bind(dir), 'notes.json', { create: true });
const writer = await call(entry.createWriter.bind(entry));
await new Promise((resolve, reject) => {
  writer.onwriteend = resolve; writer.onerror = reject;
  writer.write(new Blob([JSON.stringify([{ bookId: 2, note: 'Reread chapter 3' }])]));
});
const file = await call(entry.file.bind(entry));
const reader = new FileReader();
const text = await new Promise((resolve) => {
  reader.onloadend = () => resolve(reader.result); reader.readAsText(file);
});
({ nativeURL: entry.nativeURL, size: file.size, text });
Output
{
  nativeURL: 'file:///data/user/0/com.example.booknest/files/notes.json',
  size: 40,
  text: '[{"bookId":2,"note":"Reread chapter 3"}]'
}

adb shell run-as com.example.booknest cat files/notes.json printed the same 40 bytes. For small data, IndexedDB is simpler; use the File plugin for photos, downloads and shared files.

cordova-plugin-geolocation (5.0.0) is a permissions shim on Android: it adds the location permissions, asks for them at run time, and then hands over to the WebView's standard navigator.geolocation. The emulator's emu geo fix never reached apps here, so the location of Kota Kinabalu was fed through Android's test provider (adb shell cmd location providers set-test-provider-location gps --location 5.9804,116.0735):

Reading the current positionJavaScript
const pos = await new Promise((resolve, reject) =>
  navigator.geolocation.getCurrentPosition(resolve, reject, { timeout: 20000 }));
const { latitude, longitude, accuracy } = pos.coords;
({ latitude, longitude, accuracy });
Output
{ latitude: 5.9804, longitude: 116.0735, accuracy: 12 }

Always pass a timeout, or a phone indoors can leave the Promise pending forever.