Skip to content

Commit

Permalink
Add background location recording.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaramelDunes committed Sep 24, 2020
1 parent 3b316a2 commit 2c72c43
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 13 deletions.
6 changes: 4 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
android:name="io.flutter.app.FlutterApplication"
android:label="nofussppg"
android:label="No Fuss PPG"
android:icon="@mipmap/launcher_icon">
<activity
android:name=".MainActivity"
Expand Down Expand Up @@ -44,5 +44,7 @@
<meta-data
android:name="flutterEmbedding"
android:value="2"/>

<service android:name="changjoopark.com.flutter_foreground_plugin.FlutterForegroundService"/>
</application>
</manifest>
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'map_screen.dart';
import 'map/map_screen.dart';

void main() {
runApp(MyApp());
Expand Down
2 changes: 1 addition & 1 deletion lib/flight_map.dart → lib/map/flight_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:flutter_map/flutter_map.dart';

import 'package:nofussppg/instruments_data_source.dart';
import 'package:latlong/latlong.dart';
import 'preset_layers.dart';
import '../preset_layers.dart';

class FlightMap extends StatefulWidget {
final Stream<InstrumentsData> dataStream;
Expand Down
16 changes: 8 additions & 8 deletions lib/map_screen.dart → lib/map/map_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:latlong/latlong.dart';
import 'package:wakelock/wakelock.dart';

import 'record_button.dart';
import 'route_manager.dart';
import '../record_button.dart';
import '../route_manager.dart';
import 'flight_map.dart';
import 'instruments.dart';
import 'instruments_data_source.dart';
import 'over_cities_screen.dart';
import 'navigation_data_source.dart';
import 'navigation_info.dart';
import 'settings_screen.dart';
import '../instruments.dart';
import '../instruments_data_source.dart';
import '../over_cities_screen.dart';
import '../navigation_data_source.dart';
import '../navigation_info.dart';
import '../settings_screen.dart';

class MapScreen extends StatefulWidget {
@override
Expand Down
14 changes: 14 additions & 0 deletions lib/record_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_foreground_plugin/flutter_foreground_plugin.dart';
import 'package:path_provider/path_provider.dart';

import 'flight_recorder.dart';
Expand Down Expand Up @@ -53,13 +54,16 @@ class _RecordButtonState extends State<RecordButton> {
_recorderSubscription = null;
_flightRecorder.dispose();
_flightRecorder = null;

FlutterForegroundPlugin.stopForegroundService();
} else {
getExternalStorageDirectory().then((value) {
DateTime now = DateTime.now();
String path =
'${value.path}/${now.year}-${now.month}-${now.day}_${now.hour}-${now.minute}.csv';

File outputFile = File(path);
print('Saving trace to $path');

if (!outputFile.existsSync()) {
_flightRecorder = FlightRecorder(outputFile);
Expand All @@ -71,7 +75,17 @@ class _RecordButtonState extends State<RecordButton> {
_recorderSubscription = widget.dataSource.data.listen((event) {
_flightRecorder.appendData(event);
});
} else {
print('File already exists!');
}

// Start a foreground service to keep receiving location updates when
// the app is in the background.
// Turns out I don't need any special background location library :-)
FlutterForegroundPlugin.startForegroundService(
title: "No Fuss PPG location service",
iconName: "ic_launcher",
);
});
}
}
Expand Down
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.2"
flutter_foreground_plugin:
dependency: "direct main"
description:
name: flutter_foreground_plugin
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.0"
flutter_image:
dependency: transitive
description:
Expand Down
6 changes: 5 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:

cupertino_icons: ^0.1.3

flutter_foreground_plugin: ^0.5.0

cached_network_image: ^2.3.1

Expand All @@ -38,5 +39,8 @@ flutter:
uses-material-design: true

assets:
- assets/offline_layers/oaci_vfr
- assets/offline_layers/oaci_vfr/8/
- assets/offline_layers/oaci_vfr/9/
- assets/offline_layers/oaci_vfr/10/
- assets/offline_layers/oaci_vfr/11/
- assets/survol.png

0 comments on commit 2c72c43

Please sign in to comment.