Skip to content

Commit c40a38f

Browse files
authored
Merge pull request MaikuB#122 from MaikuB/dev
Temporarily remove code for triggering callback when a notification is shown and library updates
2 parents f4638b6 + e032630 commit c40a38f

File tree

16 files changed

+93
-164
lines changed

16 files changed

+93
-164
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# [0.4.1]
2-
* [Android/iOS] New `onShowNotification` callback for when a notification is shown that can handled when calling the `initialize` function. This uses the latest changes to the Flutter engine that supports headless execution i.e. the ability to execute Dart code without the app running. See [here](https://github.com/flutter/flutter/issues/6192) for a link to the issue in the main Flutter repository about this. Note that the function handling this callback must be top-level function as this is requirement for executing headless Dart code. The example for the plugin has been updated to provide sample code on to handle the callback. **IMPORTANT** the callback only works on Android and iOS 10+. Note support on iOS is difficult to verify at the moment since Flutter engine support for executing headless Dart code on iOS doesn't support plugins at the moment.
32
* **BREAKING CHANGE** renamed the `selectNotification` callback exposed by the `initialize` function to `onSelectNotification`
3+
* **BREAKING CHANGE** updated plugin to Android Support Library version 28.0, compile and target SDK version to 28
44
* Address issue [115](https://github.com/MaikuB/flutter_local_notifications/issues/115) by adding validation to the notification ID values. This ensure they're within the range of a 32-bit integer as notification IDs on Android need to be within that range. Note that an `ArgumentError` is thrown when a value is out of range.
5+
* Updated the Android Integration section around registering receivers via the Android manifest as per the suggestion in [116](https://github.com/MaikuB/flutter_local_notifications/issues/116)
6+
* Updated version of the http dependency for used by the example app
57

68
# [0.4.0]
79
* [Android] Fix issue [112](https://github.com/MaikuB/flutter_local_notifications/issues/112) where big picture notifications wouldn't show
@@ -14,7 +16,7 @@
1416
* Added documentation around ProGuard configuration to Android Integration section of the README
1517

1618
## [0.3.7]
17-
* [Android] Fix issues [88](https://github.com/MaikuB/flutter_local_notifications/issues/88) where cancelled notifications could reappear on reboot.
19+
* [Android] Fix issue [88](https://github.com/MaikuB/flutter_local_notifications/issues/88) where cancelled notifications could reappear on reboot.
1820

1921
## [0.3.6]
2022
* [Android] Add mapping to the setOnlyAlertOnce method [83](https://github.com/MaikuB/flutter_local_notifications/issues/83). Allows the sound, vibrate and ticker to be played if the notification is not already showing

README.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ var initializationSettings = new InitializationSettings(
6868
initializationSettingsAndroid, initializationSettingsIOS);
6969
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
7070
flutterLocalNotificationsPlugin.initialize(initializationSettings,
71-
onSelectNotification: onSelectNotification
72-
onShowNotification: onShowNotification);
71+
onSelectNotification: onSelectNotification);
7372
```
7473

75-
Here we specify we have specified the default icon to use for notifications on Android (refer to the Android Integration section) and designated the function (onSelectNotification) that should fire when a notification has been tapped on. Specifying this callback is entirely optional. In this example, it will trigger navigation to another page and display the payload associated with the notification. It is also possible to handle the `onShowNotification` that will invoke code when a notification is shown. Note that the function handling this callback must be top-level function as this is requirement for executing headless Dart code.
74+
Here we specify we have specified the default icon to use for notifications on Android (refer to the Android Integration section) and designated the function (onSelectNotification) that should fire when a notification has been tapped on. Specifying this callback is entirely optional. In this example, it will trigger navigation to another page and display the payload associated with the notification.
7675

7776
```
7877
Future onSelectNotification(String payload) async {
@@ -262,6 +261,7 @@ If your application needs the ability to schedule notifications then you need to
262261

263262
```xml
264263
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
264+
```
265265

266266
The following is also needed to ensure scheduled notifications remain scheduled upon a reboot (this is handled by the plugin)
267267

@@ -272,7 +272,6 @@ The following is also needed to ensure scheduled notifications remain scheduled
272272
</intent-filter>
273273
</receiver>
274274
```
275-
```
276275

277276
Developers will also need to add the following so that plugin can handle displaying scheduled notifications
278277

@@ -286,12 +285,6 @@ If the vibration pattern of an Android notification will be customised then add
286285
<uses-permission android:name="android.permission.VIBRATE" />
287286
```
288287

289-
If your application is looking to handle the `onShowNotification` callback, then the following permission is required
290-
291-
```xml
292-
<uses-permission android:name="android.permission.WAKE_LOCK" />
293-
```
294-
295288
Notification icons should be added as a drawable resource. The example project/code shows how to set default icon for all notifications and how to specify one for each notification. It is possible to use launcher icon/mipmap and this by default is `@mipmap/ic_launcher` in the Android manifest and can be passed `AndroidInitializationSettings` constructor. However, the offical Android guidance is that you should use drawable resources. Custom notification sounds should be added as a raw resource and the sample illustrates how to play a notification with a custom sound. Refer to the following links around Android resources and notification icons.
296289

297290
* https://developer.android.com/guide/topics/resources/providing-resources
@@ -314,15 +307,15 @@ allprojects {
314307
resolutionStrategy.eachDependency { details ->
315308
if (details.requested.group == 'com.android.support'
316309
&& !details.requested.name.contains('multidex') ) {
317-
details.useVersion "27.1.0"
310+
details.useVersion "28.0.0"
318311
}
319312
}
320313
}
321314
}
322315
}
323316
```
324317

325-
Note though this will force other plugins to use the same version of the library that this plugin depends on so may not be desirable, particularly if they use a more recent version than 27.1. If you have another suggestion on how to solve this please do let me know :)
318+
Note though this will force other plugins to use the same version of the library that this plugin depends on so may not be desirable. If you have another suggestion on how to solve this please do let me know :)
326319

327320
When doing a release build of your app, you'll likely need to customise your ProGuard configuration file as per this [link](https://developer.android.com/studio/build/shrink-code#keep-code) and add the following line
328321

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ rootProject.allprojects {
2222
apply plugin: 'com.android.library'
2323

2424
android {
25-
compileSdkVersion 27
25+
compileSdkVersion 28
2626

2727
defaultConfig {
2828
minSdkVersion 16
@@ -34,6 +34,6 @@ android {
3434
}
3535

3636
dependencies {
37-
implementation "com.android.support:support-compat:27.1.0"
37+
implementation "com.android.support:support-compat:28.0.0"
3838
implementation "com.google.code.gson:gson:2.8.2"
3939
}

android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import io.flutter.plugin.common.MethodChannel.Result;
4747
import io.flutter.plugin.common.PluginRegistry;
4848
import io.flutter.plugin.common.PluginRegistry.Registrar;
49+
import io.flutter.view.FlutterNativeView;
4950

5051
/**
5152
* FlutterLocalNotificationsPlugin
@@ -75,10 +76,10 @@ public class FlutterLocalNotificationsPlugin implements MethodCallHandler, Plugi
7576
private static final String INVALID_DRAWABLE_RESOURCE_ERROR_MESSAGE = "The resource %s could not be found. Please make sure it has been added as a drawable resource to your Android head project.";
7677
private static final String INVALID_RAW_RESOURCE_ERROR_MESSAGE = "The resource %s could not be found. Please make sure it has been added as a raw resource to your Android head project.";
7778

78-
public static final String ON_NOTIFICATION_ACTION = "onNotification";
79+
/*public static final String ON_NOTIFICATION_ACTION = "onNotification";
7980
public static final String ON_NOTIFICATION_ARGS = "onNotificationArgs";
8081
public static final String CALLBACK_DISPATCHER = "callbackDispatcher";
81-
public static final String ON_NOTIFICATION_CALLBACK_DISPATCHER = "onNotificationCallbackDispatcher";
82+
public static final String ON_NOTIFICATION_CALLBACK_DISPATCHER = "onNotificationCallbackDispatcher";*/
8283
public static final String SHARED_PREFERENCES_KEY = "notification_plugin_cache";
8384
public static String NOTIFICATION_ID = "notification_id";
8485
public static String NOTIFICATION = "notification";
@@ -485,13 +486,10 @@ public void onMethodCall(MethodCall call, Result result) {
485486
switch (call.method) {
486487

487488
case INITIALIZE_METHOD: {
489+
// initializeHeadlessService(call, result);
488490
initialize(call, result);
489491
break;
490492
}
491-
case INITIALIZE_HEADLESS_SERVICE_METHOD: {
492-
initializeHeadlessService(call, result);
493-
break;
494-
}
495493
case GET_NOTIFICATION_APP_LAUNCH_DETAILS_METHOD: {
496494
getNotificationAppLaunchDetails(result);
497495
break;
@@ -522,16 +520,20 @@ public void onMethodCall(MethodCall call, Result result) {
522520
}
523521
}
524522

525-
private void initializeHeadlessService(MethodCall call, Result result) {
523+
/*private void initializeHeadlessService(MethodCall call, Result result) {
526524
Map<String, Object> arguments = call.arguments();
527-
SharedPreferences.Editor editor = registrar.context().getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE)
528-
.edit();
525+
SharedPreferences sharedPreferences = registrar.context().getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
526+
SharedPreferences.Editor editor = sharedPreferences.edit();
529527
530-
Object callbackDispatcher = arguments.get(CALLBACK_DISPATCHER);
531-
if(callbackDispatcher instanceof Long) {
532-
editor.putLong(CALLBACK_DISPATCHER, (Long)callbackDispatcher);
533-
} else if(callbackDispatcher instanceof Integer) {
534-
editor.putLong(CALLBACK_DISPATCHER, (Integer)callbackDispatcher);
528+
if(arguments.containsKey(CALLBACK_DISPATCHER)) {
529+
Object callbackDispatcher = arguments.get(CALLBACK_DISPATCHER);
530+
if (callbackDispatcher instanceof Long) {
531+
editor.putLong(CALLBACK_DISPATCHER, (Long) callbackDispatcher);
532+
} else if (callbackDispatcher instanceof Integer) {
533+
editor.putLong(CALLBACK_DISPATCHER, (Integer) callbackDispatcher);
534+
}
535+
} else if(sharedPreferences.contains(CALLBACK_DISPATCHER)){
536+
editor.remove(CALLBACK_DISPATCHER);
535537
}
536538
537539
if(arguments.containsKey(ON_NOTIFICATION_CALLBACK_DISPATCHER)) {
@@ -541,10 +543,12 @@ private void initializeHeadlessService(MethodCall call, Result result) {
541543
} else if(onNotificationCallbackDispatcher instanceof Integer) {
542544
editor.putLong(ON_NOTIFICATION_CALLBACK_DISPATCHER, (Integer)onNotificationCallbackDispatcher);
543545
}
546+
} else if(sharedPreferences.contains(ON_NOTIFICATION_CALLBACK_DISPATCHER)){
547+
editor.remove(ON_NOTIFICATION_CALLBACK_DISPATCHER);
544548
}
545549
546550
editor.commit();
547-
}
551+
}*/
548552

549553
private void cancel(MethodCall call, Result result) {
550554
Integer id = call.arguments();
@@ -679,7 +683,7 @@ public static void showNotification(Context context, NotificationDetails notific
679683
Notification notification = createNotification(context, notificationDetails);
680684
NotificationManagerCompat notificationManagerCompat = getNotificationManager(context);
681685
notificationManagerCompat.notify(notificationDetails.id, notification);
682-
SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
686+
/*SharedPreferences sharedPreferences = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE);
683687
if(sharedPreferences.contains(ON_NOTIFICATION_CALLBACK_DISPATCHER)) {
684688
long callbackHandle = sharedPreferences.getLong(ON_NOTIFICATION_CALLBACK_DISPATCHER, 0);
685689
HashMap<String, Object> callbackArgs = new HashMap<>();
@@ -692,7 +696,7 @@ public static void showNotification(Context context, NotificationDetails notific
692696
intent.setAction(ON_NOTIFICATION_ACTION);
693697
intent.putExtra(ON_NOTIFICATION_ARGS, callbackArgs);
694698
NotificationService.enqueueWork(context, intent);
695-
}
699+
}*/
696700
}
697701

698702
private static NotificationManagerCompat getNotificationManager(Context context) {

android/src/main/java/com/dexterous/flutterlocalnotifications/NotificationService.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.dexterous.flutterlocalnotifications;
1+
/*package com.dexterous.flutterlocalnotifications;
22
33
import android.content.Context;
44
import android.content.Intent;
@@ -22,44 +22,44 @@
2222
2323
public class NotificationService extends JobIntentService implements MethodChannel.MethodCallHandler {
2424
private static final String TAG = "NotificationService";
25-
private static final String BACKGROUND_CHANNEL = "dexterous.com/flutter/local_notifications_background";
25+
private static final String BACKGROUND_CHANNEL = "dexterous.com/flutter/local_notifications";
2626
private static final int JOB_ID = (int)UUID.randomUUID().getMostSignificantBits();
2727
private static final String INITIALIZED_HEADLESS_SERVICE_METHOD = "initializedHeadlessService";
2828
private static final String ON_NOTIFICATION_METHOD = "onNotification";
29-
private static AtomicBoolean started = new AtomicBoolean(false);
29+
private static final AtomicBoolean started = new AtomicBoolean(false);
3030
private static PluginRegistrantCallback pluginRegistrantCallback;
3131
private MethodChannel backgroundChannel;
3232
private ArrayDeque onNotificationQueue = new ArrayDeque<Map<String, Object>>();
3333
private FlutterNativeView backgroundFlutterView;
3434
3535
public static void enqueueWork(Context context, Intent intent) {
36+
FlutterMain.ensureInitializationComplete(context, null);
3637
enqueueWork(context, NotificationService.class, JOB_ID, intent);
3738
}
3839
3940
private void startNotificationService(Context context) {
4041
synchronized (started) {
41-
FlutterMain.ensureInitializationComplete(context, null);
42-
43-
long callbackHandle = context.getSharedPreferences(
44-
FlutterLocalNotificationsPlugin.SHARED_PREFERENCES_KEY,
45-
Context.MODE_PRIVATE)
46-
.getLong(FlutterLocalNotificationsPlugin.CALLBACK_DISPATCHER, 0);
47-
FlutterCallbackInformation callbackInfo = FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
48-
if (callbackInfo == null) {
49-
Log.e(TAG, "Fatal: failed to find callback");
50-
return;
51-
}
52-
backgroundFlutterView = new FlutterNativeView(context, true);
53-
FlutterRunArguments args = new FlutterRunArguments();
54-
args.bundlePath = FlutterMain.findAppBundlePath(context);
55-
args.entrypoint = callbackInfo.callbackName;
56-
args.libraryPath = callbackInfo.callbackLibraryPath;
57-
backgroundFlutterView.runFromBundle(args);
58-
if (pluginRegistrantCallback != null) {
59-
pluginRegistrantCallback.registerWith(backgroundFlutterView.getPluginRegistry());
42+
if(backgroundFlutterView == null) {
43+
long callbackHandle = context.getSharedPreferences(
44+
FlutterLocalNotificationsPlugin.SHARED_PREFERENCES_KEY,
45+
Context.MODE_PRIVATE)
46+
.getLong(FlutterLocalNotificationsPlugin.CALLBACK_DISPATCHER, 0);
47+
FlutterCallbackInformation callbackInfo = FlutterCallbackInformation.lookupCallbackInformation(callbackHandle);
48+
if (callbackInfo == null) {
49+
Log.e(TAG, "Fatal: failed to find callback");
50+
return;
51+
}
52+
backgroundFlutterView = new FlutterNativeView(context, true);
53+
if (pluginRegistrantCallback != null) {
54+
pluginRegistrantCallback.registerWith(backgroundFlutterView.getPluginRegistry());
55+
}
56+
FlutterRunArguments args = new FlutterRunArguments();
57+
args.bundlePath = FlutterMain.findAppBundlePath(context);
58+
args.entrypoint = callbackInfo.callbackName;
59+
args.libraryPath = callbackInfo.callbackLibraryPath;
60+
backgroundFlutterView.runFromBundle(args);
6061
}
6162
62-
6363
}
6464
backgroundChannel = new MethodChannel(backgroundFlutterView, BACKGROUND_CHANNEL);
6565
backgroundChannel.setMethodCallHandler(this);
@@ -111,4 +111,4 @@ public void onMethodCall(MethodCall call, MethodChannel.Result result) {
111111
result.notImplemented();
112112
}
113113
}
114-
}
114+
}*/

example/android/app/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ apply plugin: 'com.android.application'
1515
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
1616

1717
android {
18-
compileSdkVersion 27
18+
compileSdkVersion 28
1919

2020
lintOptions {
2121
disable 'InvalidPackage'
@@ -25,7 +25,7 @@ android {
2525
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
2626
applicationId "com.dexterous.flutterlocalnotificationsexample"
2727
minSdkVersion 16
28-
targetSdkVersion 27
28+
targetSdkVersion 28
2929
versionCode 1
3030
versionName "1.0"
3131
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -48,5 +48,5 @@ dependencies {
4848
testImplementation 'junit:junit:4.12'
4949
androidTestImplementation 'com.android.support.test:runner:1.0.1'
5050
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
51-
implementation "com.android.support:support-compat:27.1.0"
51+
implementation "com.android.support:support-compat:28.0.0"
5252
}

example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
additional functionality it is fine to subclass or reimplement
1717
FlutterApplication and put your custom class here. -->
1818
<application
19-
android:name=".Application"
19+
android:name="io.flutter.app.FlutterApplication"
2020
android:label="flutter_local_notifications_example"
2121
android:icon="@mipmap/ic_launcher">
2222
<activity
@@ -44,9 +44,5 @@
4444
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
4545
</intent-filter>
4646
</receiver>
47-
<service
48-
android:name="com.dexterous.flutterlocalnotifications.NotificationService"
49-
android:permission="android.permission.BIND_JOB_SERVICE"
50-
android:exported="true"/>
5147
</application>
5248
</manifest>

example/android/app/src/main/java/com/dexterous/flutterlocalnotificationsexample/Application.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.dexterous.flutterlocalnotificationsexample;
1+
/*package com.dexterous.flutterlocalnotificationsexample;
22
33
import com.dexterous.flutterlocalnotifications.NotificationService;
44
@@ -17,4 +17,4 @@ public void onCreate() {
1717
public void registerWith(PluginRegistry registry) {
1818
GeneratedPluginRegistrant.registerWith(registry);
1919
}
20-
}
20+
}*/

example/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
}
66

77
dependencies {
8-
classpath 'com.android.tools.build:gradle:3.1.3'
8+
classpath 'com.android.tools.build:gradle:3.2.1'
99
}
1010
}
1111

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Thu Mar 29 16:20:55 AEDT 2018
1+
#Sat Nov 10 09:17:46 AEDT 2018
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

0 commit comments

Comments
 (0)