Skip to content

Commit

Permalink
[flutter_local_notifications] add docs on request permission to show …
Browse files Browse the repository at this point in the history
…notification on Android (MaikuB#1675)

* add docs on request permission to show notification on Android

* Google Java Format

Co-authored-by: github-actions <>
  • Loading branch information
MaikuB authored Aug 17, 2022
1 parent d3553c5 commit 52af054
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions flutter_local_notifications/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [9.8.0]

* [Android] added `requestPermission` method to the `AndroidFlutterLocalNotificationsPlugin` class. This make use of the new feature added to Android 13 where an app can request permissions to show notifications. This isn't a breaking change but requires the Android 13 SDK installed and only apps targeting Android 13 can request the permission. The latter can be done by updating the targetSdkVersion in an app's `build.gradle` file to `33`. Thanks to the PR from [Bartek Pacia](https://github.com/bartekpacia). **Note**: the ability to request the permission as part of calling `initialize` will be added later on

# [9.7.1]

* [Android] updated how launch intent is read on Android for the `getNotificationAppLaunchDetails` method
Expand Down
11 changes: 11 additions & 0 deletions flutter_local_notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ A cross platform plugin for displaying local notifications.
- **[📷 Screenshots](#-screenshots)**
- **[👏 Acknowledgements](#-acknowledgements)**
- **[🔧 Android Setup](#-android-setup)**
- [Requesting permissions on Android 13 or higher](#requesting-permissions-on-android-13-or-higher)
- [Custom notification icons and sounds](#custom-notification-icons-and-sounds)
- [Scheduled notifications](#scheduling-a-notification)
- [Fullscreen intent notifications](#full-screen-intent-notifications)
Expand Down Expand Up @@ -65,6 +66,7 @@ A cross platform plugin for displaying local notifications.
* Specify a custom notification sound
* Ability to handle when a user has tapped on a notification, when the app is in the foreground, background or is terminated
* Determine if an app was launched due to tapping on a notification
* [Android] Request permission to show notifications
* [Android] Configuring the importance level
* [Android] Configuring the priority
* [Android] Customising the vibration pattern for notifications
Expand Down Expand Up @@ -164,6 +166,15 @@ To respond to notification after the application is terminated, your application

Before proceeding, please make sure you are using the latest version of the plugin. The reason for this is that since version 3.0.1+4, the amount of setup needed has been reduced. Previously, applications needed changes done to the `AndroidManifest.xml` file and there was a bit more setup needed for release builds. If for some reason, your application still needs to use an older version of the plugin then make use of the release tags to refer back to older versions of readme.

### Requesting permissions on Android 13 or higher

From Android 13 (API level 33) onwards, apps now have the ability to display a prompt where users can decide if they want to grant an app permission to show notifications. For further reading on this matter read https://developer.android.com/guide/topics/ui/notifiers/notification-permission. To support this applications need target their application to Android 13 or higher. For example, to target Android 13, update your app's `build.gradle` file to have a `targetSdkVersion` of `33`. Applications can then call the following code to request the permission where the `requestPermission` method is associated with the `AndroidFlutterLocalNotificationsPlugin` class (i.e. the Android implementation of the plugin)

```
flutterLocalNotificationsPlugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>().requestPermission();
```

### Custom 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.
Expand Down
2 changes: 1 addition & 1 deletion flutter_local_notifications/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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: 9.7.1
version: 9.8.0
homepage: https://github.com/MaikuB/flutter_local_notifications/tree/master/flutter_local_notifications

dependencies:
Expand Down

0 comments on commit 52af054

Please sign in to comment.