Skip to content

Commit 18da9d5

Browse files
authored
[flutter_local_notifications] renamed requestPermission method on Android to requestNotificationsPermission (#2053)
* renamed requestPermission method on Android to requestNotificationsPermission * Google Java Format --------- Co-authored-by: github-actions <>
1 parent fa27ae2 commit 18da9d5

File tree

5 files changed

+19
-8
lines changed

5 files changed

+19
-8
lines changed

flutter_local_notifications/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# [16.0.0-dev.1]
22

3-
* [Android] **Breaking changes** the plugin now only declares the bare minimum in its `AndroidManifest.xml`. This means applications making use of either scheduled notifications, full-screen intent notifications or notification actions will now require changes in the application's own `AndroidManifest.xml` file. Please check the [AndroidManifest.xml setup](https://pub.dev/packages/flutter_local_notifications#androidmanifestxml-setup) section of the readme for more details. The reason this was done was because not all applications will leverage all of the plugin's features. Doing this will now allow applications to only request the appropriate permissions needed for their application. This addresses issue [1687](https://github.com/MaikuB/flutter_local_notifications/issues/1687)
3+
* [Android] **Breaking change** renamed the `requestPermission()` associated with the `AndroidFlutterLocalNotificationsPlugin` class to `requestNotificationsPermission()`. This was done to be more explicit given another method (`requestExactAlarmsPermission()`) has been added that also requests a permission (more details below).
4+
* [Android] **Breaking change** the plugin now only declares the bare minimum in its `AndroidManifest.xml`. This means applications making use of either scheduled notifications, full-screen intent notifications or notification actions will now require changes in the application's own `AndroidManifest.xml` file. Please check the [AndroidManifest.xml setup](https://pub.dev/packages/flutter_local_notifications#androidmanifestxml-setup) section of the readme for more details. The reason this was done was because not all applications will leverage all of the plugin's features. Doing this will now allow applications to only request the appropriate permissions needed for their application. This addresses issue [1687](https://github.com/MaikuB/flutter_local_notifications/issues/1687)
45
* [Android] added the ability to request permission to schedule exact alarms via the `requestExactAlarmsPermission()` method that has been added to the `AndroidFlutterLocalNotificationsPlugin` class that represents the Android implementation of the plugin. This has been done in response to behaviour changes introduced in Android 14 (API level 34) when comes to using exact alarms. See the official documentation about these changes [here](https://developer.android.com/about/versions/14/changes/schedule-exact-alarms). This change addresses issue [1906](https://github.com/MaikuB/flutter_local_notifications/issues/1906)
56

67

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ public class FlutterLocalNotificationsPlugin
158158
private static final String PERIODICALLY_SHOW_METHOD = "periodicallyShow";
159159
private static final String GET_NOTIFICATION_APP_LAUNCH_DETAILS_METHOD =
160160
"getNotificationAppLaunchDetails";
161-
private static final String REQUEST_PERMISSION_METHOD = "requestPermission";
161+
private static final String REQUEST_NOTIFICATIONS_PERMISSION_METHOD =
162+
"requestNotificationsPermission";
162163
private static final String REQUEST_EXACT_ALARMS_PERMISSION_METHOD =
163164
"requestExactAlarmsPermission";
164165
private static final String METHOD_CHANNEL = "dexterous.com/flutter/local_notifications";
@@ -1394,8 +1395,8 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
13941395
case ZONED_SCHEDULE_METHOD:
13951396
zonedSchedule(call, result);
13961397
break;
1397-
case REQUEST_PERMISSION_METHOD:
1398-
requestPermission(
1398+
case REQUEST_NOTIFICATIONS_PERMISSION_METHOD:
1399+
requestNotificationsPermission(
13991400
new PermissionRequestListener() {
14001401
@Override
14011402
public void complete(boolean granted) {
@@ -1741,7 +1742,7 @@ private void cancelAllNotifications(Result result) {
17411742
result.success(null);
17421743
}
17431744

1744-
public void requestPermission(@NonNull PermissionRequestListener callback) {
1745+
public void requestNotificationsPermission(@NonNull PermissionRequestListener callback) {
17451746
if (permissionRequestProgress != PermissionRequestProgress.None) {
17461747
callback.fail(PERMISSION_REQUEST_IN_PROGRESS_ERROR_MESSAGE);
17471748
return;

flutter_local_notifications/example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class _HomePageState extends State<HomePage> {
304304
AndroidFlutterLocalNotificationsPlugin>();
305305

306306
final bool? grantedNotificationPermission =
307-
await androidImplementation?.requestPermission();
307+
await androidImplementation?.requestNotificationsPermission();
308308
setState(() {
309309
_notificationsEnabled = grantedNotificationPermission ?? false;
310310
});

flutter_local_notifications/lib/src/platform_flutter_local_notifications.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ class AndroidFlutterLocalNotificationsPlugin
162162
/// See also:
163163
///
164164
/// * https://developer.android.com/about/versions/13/changes/notification-permission
165-
Future<bool?> requestPermission() async =>
166-
_channel.invokeMethod<bool>('requestPermission');
165+
Future<bool?> requestNotificationsPermission() async =>
166+
_channel.invokeMethod<bool>('requestNotificationsPermission');
167167

168168
/// Schedules a notification to be shown at the specified date and time
169169
/// relative to a specific time zone.

flutter_local_notifications/test/android_flutter_local_notifications_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,15 @@ void main() {
25082508
));
25092509
});
25102510

2511+
test('requestNotificationsPermission', () async {
2512+
await flutterLocalNotificationsPlugin
2513+
.resolvePlatformSpecificImplementation<
2514+
AndroidFlutterLocalNotificationsPlugin>()!
2515+
.requestNotificationsPermission();
2516+
expect(log.last,
2517+
isMethodCall('requestNotificationsPermission', arguments: null));
2518+
});
2519+
25112520
test('requestExactAlarmsPermission', () async {
25122521
await flutterLocalNotificationsPlugin
25132522
.resolvePlatformSpecificImplementation<

0 commit comments

Comments
 (0)