Skip to content

Commit

Permalink
[flutter_local_notifications] updated platform-specific integration s…
Browse files Browse the repository at this point in the history
…ections in the readme (#504)

* updated platform-specific integration sections

* add link to custom notification sound file mentioned in readme

* tweak wording on configuring resource shrinking

* tweaks to changelog and readme title
  • Loading branch information
MaikuB authored Feb 28, 2020
1 parent 678bb9b commit aa3c384
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This repository consists hosts the following packages
- `flutter_local_notifications`: code for the cross-platform facing plugin used to display local notifications within Flutter applications
- `flutter_local_notifications_platform_interface`: the code for the common platform interface

These can be found in the corresponding directories within the same name. Most developers are like here as they are looking to use the `flutter_local_notifications` plugin. There is a readme file within each directory with more information.
These can be found in the corresponding directories within the same name. Most developers are likely here as they are looking to use the `flutter_local_notifications` plugin. There is a readme file within each directory with more information.

## Issues

Expand Down
6 changes: 6 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [1.2.0+4]

* Title at the top of the readme is now the same name as the plugin
* Updated readme to add subsections under the Android and iOS integration guide
* Added links in the readme under the Android release build configuration section that point to the configuration files used by the example app

# [1.2.0+3]

* Updated API docs for `resolvePlatformSpecificImplementation()` method
Expand Down
26 changes: 19 additions & 7 deletions flutter_local_notifications/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Flutter Local Notifications Plugin
# flutter_local_notifications

[![pub package](https://img.shields.io/pub/v/flutter_local_notifications.svg)](https://pub.dartlang.org/packages/flutter_local_notifications)
[![Build Status](https://api.cirrus-ci.com/github/MaikuB/flutter_local_notifications.svg)](https://cirrus-ci.com/github/MaikuB/flutter_local_notifications/master)
Expand Down Expand Up @@ -320,9 +320,11 @@ await flutterLocalNotificationsPlugin.cancelAll();

This should cover the basic functionality. Please check out the `example` directory for a sample app that illustrates the rest of the functionality available and refer to the API docs for more information. Also read the below on what you need to configure on each platform

## Android Integration
## Android integration

If your application needs the ability to schedule notifications then you need to request permissions to be notified when the phone has been booted as scheduled notifications uses the `AlarmManager` API to determine when notifications should be displayed. However, they are cleared when a phone has been turned off. Requesting permission requires adding the following to the manifest
### Configuration for scheduled notifications

If your application needs the ability to schedule notifications then you need to request permissions to be notified when the phone has been booted as scheduled notifications uses the `AlarmManager` API to determine when notifications should be displayed. However, they are cleared when a phone has been turned off. Requesting permission requires adding the following to the manifest (i.e. your application's `AndroidManifest.xml` file)

```xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
Expand Down Expand Up @@ -350,6 +352,10 @@ If the vibration pattern of an Android notification will be customised then add
<uses-permission android:name="android.permission.VIBRATE" />
```

For reference, the example app's `AndroidManifest.xml` file can be found [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/AndroidManifest.xml)

### Adding notification icons and sounds

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.

* https://developer.android.com/guide/topics/resources/providing-resources
Expand All @@ -360,19 +366,23 @@ When specifying the large icon bitmap or big picture bitmap (associated with the

Note that with Android 8.0+, sounds and vibrations are associated with notification channels and can only be configured when they are first created. Showing/scheduling a notification will create a channel with the specified id if it doesn't exist already. If another notification specifies the same channel id but tries to specify another sound or vibration pattern then nothing occurs.

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.
### Release build configuration

When doing a release build of your app, which is the default setting when building an APK or app bundle, 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.

```
-keep class com.dexterous.** { *; }
```

The plugin also makes use of GSON and the Proguard rules can be found [here](https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg). The example app has a consolidate Proguard rules (`proguard-rules.pro`) file that combines these together for reference.
The plugin also makes use of GSON and the Proguard rules can be found [here](https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg). The example app has a consolidated Proguard rules (`proguard-rules.pro`) file that combines these together for reference [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/proguard-rules.pro).

If you have resource shrinking enabled, ensure that you have customised the resources that should be kept so that things like your notification images aren't discarded by following the instructions [here](https://developer.android.com/studio/build/shrink-code#keep-resources).
You will also need to ensure that you have configured the resources that should be kept so that resources like your notification icons aren't discarded by the R8 compiler by following the instructions [here](https://developer.android.com/studio/build/shrink-code#keep-resources). Without doing this, you might not see the icon you've specified in your app's notifications. The configuration used by the example app can be found [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/res/raw/keep.xml) where it is specifying that all drawable resources should be kept, as well as the file used to play a custom notification sound (sound file is located [here](https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/example/android/app/src/main/res/raw/slow_spring_board.mp3)).

**IMPORTANT**: Starting from version 0.5.0, this library no longer uses the deprecated Android support libraries and has migrated to AndroidX. Developers may require migrating their apps to support this following [this guide](https://developer.android.com/jetpack/androidx/migrate)

## iOS Integration
## iOS integration

### General setup

Add the following lines to the `didFinishLaunchingWithOptions` method in the AppDelegate.m/AppDelegate.swift file of your iOS project

Expand Down Expand Up @@ -454,6 +464,8 @@ if(!UserDefaults.standard.bool(forKey: "Notification")) {
}
```

### Custom notification sound restrictions

When using custom notification sound, developers should be aware that iOS enforces restrictions on this (e.g. supported file formats). As of this writing, this is documented by Apple at

https://developer.apple.com/documentation/usernotifications/unnotificationsound?language=objc
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_local_notifications
description: A cross platform plugin for displaying and scheduling local notifications for Flutter applications with the ability to customise for each platform.
version: 1.2.0+3
version: 1.2.0+4
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications

dependencies:
Expand Down

0 comments on commit aa3c384

Please sign in to comment.