Skip to content

Commit

Permalink
remove: Remove flutter_foreground_task plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Dev-hwang committed Jun 5, 2024
1 parent 2d85a99 commit 1f89156
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 218 deletions.
219 changes: 51 additions & 168 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ This plugin is a geofence service with activity recognition API. It does not use
* `Geofence` can have multiple radius.
* `Geofence` can see what activity took place when the device entered the radius.
* `GeofenceService` can perform geo-fencing in real time and catch errors during operation.
* `GeofenceService` can be operated in the background using `WillStartForegroundTask` widget.

**WAIT**: This plugin performs geo-fencing based on a circular geofence. If you want to create a polygon geofence, this [plugin](https://pub.dev/packages/poly_geofence_service) is recommended.

Expand All @@ -31,23 +30,6 @@ Since geo-fencing operates based on location, we need to add the following permi
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
```
If you want to run the service in the background, add the following permission. If your project supports Android 10, be sure to add the `ACCESS_BACKGROUND_LOCATION` permission.
```
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
```
And specify the service inside the `<application>` tag as follows.
```
<service
android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
android:foregroundServiceType="location"
android:stopWithTask="true" />
```
The biggest feature of this plugin is that it can know user activity while geo-fencing. Please specify the permission usage in `<manifest>` tag.
```
Expand All @@ -65,70 +47,13 @@ Like Android platform, geo-fencing is based on location, we need to add the foll
<string>Used to provide geofence service.</string>
```
If you want to run the service in the background, add the following description.
```
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Used to provide geofence services in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Used to provide geofence services in the background.</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
</array>
```
To detect changes in user activity, add the following description.
```
<key>NSMotionUsageDescription</key>
<string>Used to recognize user activity information.</string>
```
(**Optional**) To display a notification when your app enters the background, you need to open the `ios/Runner/AppDelegate` file and set the following:
**Objective-C**:
```objectivec
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[GeneratedPluginRegistrant registerWithRegistry:self];
// here
if (@available(iOS 10.0, *)) {
[UNUserNotificationCenter currentNotificationCenter].delegate = (id<UNUserNotificationCenterDelegate>) self;
}
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
```

**Swift**:

```swift
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)

// here
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
```

## How to use
1. Create a `GeofenceService` instance and set options. `GeofenceService.instance.setup()` provides the following options:
Expand Down Expand Up @@ -247,49 +172,7 @@ void initState() {
}
```

4. Add `WillStartForegroundTask` widget for background execution on Android platform. `WillStartForegroundTask` provides the following options:
* `onWillStart`: Called to ask if you want to start the foreground task.
* `notificationOptions`: Optional values for notification detail settings.
* `notificationTitle`: The title that will be displayed in the notification.
* `notificationText`: The text that will be displayed in the notification.
* `child`: A child widget that contains the `Scaffold` widget.

```dart
@override
Widget build(BuildContext context) {
return MaterialApp(
// A widget used when you want to start a foreground task when trying to minimize or close the app.
// Declare on top of the [Scaffold] widget.
home: WillStartForegroundTask(
onWillStart: () async {
// You can add a foreground task start condition.
return _geofenceService.isRunningService;
},
androidNotificationOptions: AndroidNotificationOptions(
channelId: 'geofence_service_notification_channel',
channelName: 'Geofence Service Notification',
channelDescription: 'This notification appears when the geofence service is running in the background.',
channelImportance: NotificationChannelImportance.LOW,
priority: NotificationPriority.LOW,
isSticky: false,
),
iosNotificationOptions: const IOSNotificationOptions(),
foregroundTaskOptions: const ForegroundTaskOptions(),
notificationTitle: 'Geofence Service is running',
notificationText: 'Tap to return to the app',
child: Scaffold(
appBar: AppBar(
title: const Text('Geofence Service'),
centerTitle: true,
),
body: _buildContentView(),
),
),
);
}
```

5. To add or remove `Geofence` while the service is running, use the following function:
4. To add or remove `Geofence` while the service is running, use the following function:

```text
_geofenceService.addGeofence(Object);
Expand All @@ -300,14 +183,14 @@ _geofenceService.removeGeofenceById(String);
_geofenceService.clearGeofenceList();
```

6. If you want to pause or resume the service, use the function below.
5. If you want to pause or resume the service, use the function below.

```text
_geofenceService.pause();
_geofenceService.resume();
```

7. When you are finished using the service, unregister the listener and call `GeofenceService.instance.stop()`.
6. When you are finished using the service, unregister the listener and call `GeofenceService.instance.stop()`.

```text
_geofenceService.removeGeofenceStatusChangeListener(_onGeofenceStatusChanged);
Expand All @@ -327,94 +210,94 @@ _geofenceService.stop();

A model representing a geofence.

| Property | Description |
|---|---|
| `id` | Identifier for `Geofence`. |
| `data` | Custom data for `Geofence`. |
| `latitude` | The latitude of geofence center. |
| `longitude` | The longitude of geofence center. |
| `radius` | The radius of `Geofence`. |
| `status` | The status of `Geofence`. |
| `timestamp` | The timestamp of `Geofence`. |
| Property | Description |
|---------------------|--------------------------------------------|
| `id` | Identifier for `Geofence`. |
| `data` | Custom data for `Geofence`. |
| `latitude` | The latitude of geofence center. |
| `longitude` | The longitude of geofence center. |
| `radius` | The radius of `Geofence`. |
| `status` | The status of `Geofence`. |
| `timestamp` | The timestamp of `Geofence`. |
| `remainingDistance` | The remaining distance to the destination. |

### :chicken: GeofenceRadius

A model representing the radius of `Geofence`.

| Property | Description |
|---|---|
| `id` | Identifier for `GeofenceRadius`. |
| `data` | Custom data for `GeofenceRadius`. |
| `length` | The length of the radius in meters. |
| `status` | The status of `GeofenceRadius`. |
| `activity` | The user activity when geofence status changes. |
| `speed` | The passing speed when geofence status changes. |
| `timestamp` | The timestamp when geofence status changes. |
| `remainingDistance` | The remaining distance to the radius. |
| Property | Description |
|---------------------|-------------------------------------------------|
| `id` | Identifier for `GeofenceRadius`. |
| `data` | Custom data for `GeofenceRadius`. |
| `length` | The length of the radius in meters. |
| `status` | The status of `GeofenceRadius`. |
| `activity` | The user activity when geofence status changes. |
| `speed` | The passing speed when geofence status changes. |
| `timestamp` | The timestamp when geofence status changes. |
| `remainingDistance` | The remaining distance to the radius. |

### :chicken: GeofenceStatus

Defines the type of the geofence status.

| Value | Description |
|---|---|
| `ENTER` | Occurs when entering the geofence radius. |
| `EXIT` | Occurs when exiting the geofence radius. |
| Value | Description |
|---------|---------------------------------------------------------------------------|
| `ENTER` | Occurs when entering the geofence radius. |
| `EXIT` | Occurs when exiting the geofence radius. |
| `DWELL` | Occurs when the loitering delay elapses after entering the geofence area. |

### :chicken: Activity

A model representing the user's activity.

| Property | Description |
|---|---|
| `type` | The type of activity recognized. |
| Property | Description |
|--------------|----------------------------------------|
| `type` | The type of activity recognized. |
| `confidence` | The confidence of activity recognized. |

### :chicken: ActivityType

Defines the type of activity.

| Value | Description |
|---|---|
| `IN_VEHICLE` | The device is in a vehicle, such as a car. |
| `ON_BICYCLE` | The device is on a bicycle. |
| `RUNNING` | The device is on a user who is running. This is a sub-activity of ON_FOOT. |
| `STILL` | The device is still (not moving). |
| `WALKING` | The device is on a user who is walking. This is a sub-activity of ON_FOOT. |
| `UNKNOWN` | Unable to detect the current activity. |
| Value | Description |
|--------------|----------------------------------------------------------------------------|
| `IN_VEHICLE` | The device is in a vehicle, such as a car. |
| `ON_BICYCLE` | The device is on a bicycle. |
| `RUNNING` | The device is on a user who is running. This is a sub-activity of ON_FOOT. |
| `STILL` | The device is still (not moving). |
| `WALKING` | The device is on a user who is walking. This is a sub-activity of ON_FOOT. |
| `UNKNOWN` | Unable to detect the current activity. |

### :chicken: ActivityConfidence

Defines the confidence of activity.

| Value | Description |
|---|---|
| `HIGH` | High accuracy: 75~100 |
| Value | Description |
|----------|------------------------|
| `HIGH` | High accuracy: 75~100 |
| `MEDIUM` | Medium accuracy: 50~75 |
| `LOW` | Low accuracy: 0~50 |
| `LOW` | Low accuracy: 0~50 |

### :chicken: GeofenceRadiusSortType

Defines the sort type of the geofence radius. If you have set multiple radius for one geofence, multiple radius can come in at the same time. At this time, you can control the order in which the radius comes in by referring to the radius meters.

| Value | Description |
|---|---|
| `ASC` | Sort the meters in ascending order. |
| Value | Description |
|--------|--------------------------------------|
| `ASC` | Sort the meters in ascending order. |
| `DESC` | Sort the meters in descending order. |

### :chicken: ErrorCodes

Error codes that may occur in the service.

| Value | Description |
|---|---|
| `ALREADY_STARTED` | Occurs when the service has already been started but the start function is called. |
| `LOCATION_SERVICES_DISABLED` | Occurs when location services are disabled. When this error occurs, you should notify the user and request activation. |
| `LOCATION_PERMISSION_DENIED` | Occurs when location permission is denied. |
| `LOCATION_PERMISSION_PERMANENTLY_DENIED` | Occurs when location permission is permanently denied. In this case, the user must manually allow the permission. |
| `ACTIVITY_RECOGNITION_PERMISSION_DENIED` | Occurs when activity recognition permission is denied. |
| Value | Description |
|------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
| `ALREADY_STARTED` | Occurs when the service has already been started but the start function is called. |
| `LOCATION_SERVICES_DISABLED` | Occurs when location services are disabled. When this error occurs, you should notify the user and request activation. |
| `LOCATION_PERMISSION_DENIED` | Occurs when location permission is denied. |
| `LOCATION_PERMISSION_PERMANENTLY_DENIED` | Occurs when location permission is permanently denied. In this case, the user must manually allow the permission. |
| `ACTIVITY_RECOGNITION_PERMISSION_DENIED` | Occurs when activity recognition permission is denied. |
| `ACTIVITY_RECOGNITION_PERMISSION_PERMANENTLY_DENIED` | Occurs when activity recognition permission is permanently denied. In this case, the user must manually allow the permission. |

## Support
Expand Down
7 changes: 0 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
Expand Down Expand Up @@ -41,11 +39,6 @@
</intent-filter>
</activity>

<service
android:name="com.pravera.flutter_foreground_task.service.ForegroundService"
android:foregroundServiceType="location"
android:stopWithTask="true" />

<!-- Don't delete the meta-data below.
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
<meta-data
Expand Down
5 changes: 0 additions & 5 deletions example/ios/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ import Flutter
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)

if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}

return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
9 changes: 0 additions & 9 deletions example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@
<false/>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Used to provide geofence service.</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Used to provide geofence services in the background.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>Used to provide geofence services in the background.</string>
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>location</string>
</array>
<key>NSMotionUsageDescription</key>
<string>Used to recognize user activity information.</string>
</dict>
Expand Down
Loading

0 comments on commit 1f89156

Please sign in to comment.