Skip to content

Commit

Permalink
Merge pull request #5 from radarlabs/notification-action
Browse files Browse the repository at this point in the history
customizable notification behavior
  • Loading branch information
nickpatrick authored Mar 10, 2021
2 parents 72cb20e + d505140 commit d23118e
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 3.0.1

- Supports `startForegroundService({'clickable': true})` to make the foreground service notification clickable, or `startForegroundService({'clickable': false})` to make it not clickable. Default is `false`.

# 3.0.0

- Updates `requestPermissions(background)` to complete only when the permissions request completes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,12 +896,15 @@ public void startForegroundService(MethodCall call, Result result) {
String icon = call.argument("icon");
String importance = call.argument("importance");
String id = call.argument("id");
boolean clickable = call.hasArgument("clickable") ? (boolean)call.argument("clickable") : false;

intent.setAction("start");
intent.putExtra("title", title)
.putExtra("text", text)
.putExtra("icon", icon)
.putExtra("importance", importance)
.putExtra("id", id)
.putExtra("clickable", clickable)
.putExtra("activity", mActivity.getClass().getCanonicalName());
mContext.startForegroundService(intent);
result.success(true);
Expand Down
24 changes: 14 additions & 10 deletions android/src/main/java/io/radar/flutter/RadarForegroundService.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@ private void startPluginForegroundService(Bundle extras) {
manager.deleteNotificationChannel("location");

Integer importance;

try {
importance = Integer.parseInt((String) extras.get("importance"));
importance = Integer.parseInt((String)extras.get("importance"));
} catch (NumberFormatException e) {
importance = 1;
}
Expand All @@ -55,15 +54,20 @@ private void startPluginForegroundService(Bundle extras) {
NotificationChannel channel = new NotificationChannel("location", "Location", importance);
getSystemService(NotificationManager.class).createNotificationChannel(channel);

int icon = getResources().getIdentifier((String) extras.get("icon"), "drawable", context.getPackageName());
int icon = getResources().getIdentifier((String)extras.get("icon"), "drawable", context.getPackageName());

PendingIntent pendingIntent;
try {
Class activityClass = Class.forName((String) extras.get("activity"));
Intent intent = new Intent(this, activityClass);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
} catch (ClassNotFoundException e) {
Boolean clickable = (Boolean) extras.getBoolean("clickable");
if (clickable) {
try {
Class activityClass = Class.forName((String)extras.get("activity"));
Intent intent = new Intent(this, activityClass);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
} catch (ClassNotFoundException e) {
pendingIntent = null;
}
} else {
pendingIntent = null;
}

Expand All @@ -78,7 +82,7 @@ private void startPluginForegroundService(Bundle extras) {

Integer id;
try {
id = Integer.parseInt((String) extras.get("id"));
id = Integer.parseInt((String)extras.get("id"));
} catch (NumberFormatException e) {
id = 0;
}
Expand Down
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class _MyAppState extends State<MyApp> {
'text': 'Continuous tracking started',
'icon': 'car_icon',
'importance': '2',
'id': '12555541'
'id': '12555541',
'clickable': true
});
},
child: Text('startForegroundService(), Android only'),
Expand Down
2 changes: 1 addition & 1 deletion ios/flutter_radar.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'flutter_radar'
s.version = '3.0.0'
s.version = '3.0.1'
s.summary = 'Flutter package for Radar, the leading geofencing and location tracking platform'
s.description = 'Flutter package for Radar, the leading geofencing and location tracking platform'
s.homepage = 'http://example.com'
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_radar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class Radar {
}

static Future startForegroundService(
Map<String, String> foregroundServiceOptions) async {
Map<String, dynamic> foregroundServiceOptions) async {
try {
await _channel.invokeMethod(
'startForegroundService', foregroundServiceOptions);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_radar
description: Flutter package for Radar, the leading geofencing and location tracking platform
version: 3.0.0
version: 3.0.1
homepage: https://github.com/radarlabs/flutter-radar

environment:
Expand Down

0 comments on commit d23118e

Please sign in to comment.