Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [1.5.2] - 15th Mart 2024

* Removed unnecessary requestAuthorizationWithOptions for iOS, this plugin doesn't need it to show badges. This should be used only for remote push notification.

## [1.5.1] - 2nd January 2024

* Fixed an issue with missing Gradle namespace and other related issues.
* Resolved an issue with the Java target SDK.
* Adjusted Dart SDK constraint to exclusively support Dart null-safety and Flutter null-safety versions.
* Corrected the usage of old Flutter embedding in the example app.
* Updated the wrapper to support the new Gradle version.

## [1.5.0] - 16th September 2022

* PR #52 (Don't overwrite categories on iOS)
Expand Down
12 changes: 9 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.android.tools.build:gradle:7.3.1'
}
}

Expand All @@ -22,18 +22,24 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdkVersion 33

defaultConfig {
minSdkVersion 16
minSdkVersion 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
}

if (project.android.hasProperty('namespace')) {
namespace 'fr.g123k.flutterappbadge.flutterappbadger'
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
4 changes: 1 addition & 3 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fr.g123k.flutterappbadge.flutterappbadger">
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import android.content.Context;

import androidx.annotation.NonNull;

import io.flutter.embedding.engine.plugins.FlutterPlugin;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
Expand Down Expand Up @@ -30,23 +32,28 @@ public void onAttachedToEngine(FlutterPluginBinding flutterPluginBinding) {
}

@Override
public void onDetachedFromEngine(FlutterPluginBinding flutterPluginBinding) {
public void onDetachedFromEngine(@NonNull FlutterPluginBinding flutterPluginBinding) {
channel.setMethodCallHandler(null);
applicationContext = null;
}

@Override
public void onMethodCall(MethodCall call, Result result) {
if (call.method.equals("updateBadgeCount")) {
ShortcutBadger.applyCount(applicationContext, Integer.valueOf(call.argument("count").toString()));
result.success(null);
} else if (call.method.equals("removeBadge")) {
ShortcutBadger.removeCount(applicationContext);
result.success(null);
} else if (call.method.equals("isAppBadgeSupported")) {
result.success(ShortcutBadger.isBadgeCounterSupported(applicationContext));
} else {
result.notImplemented();
public void onMethodCall(MethodCall call, @NonNull Result result) {
switch (call.method) {
case "updateBadgeCount":
ShortcutBadger.applyCount(applicationContext, Integer.valueOf(call.argument("count").toString()));
result.success(null);
break;
case "removeBadge":
ShortcutBadger.removeCount(applicationContext);
result.success(null);
break;
case "isAppBadgeSupported":
result.success(ShortcutBadger.isBadgeCounterSupported(applicationContext));
break;
default:
result.notImplemented();
break;
}
}
}
11 changes: 8 additions & 3 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 29
compileSdk = 33

lintOptions {
disable 'InvalidPackage'
Expand All @@ -24,8 +24,8 @@ android {
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "fr.g123k.flutterappbadger.flutterappbadgerexample"
minSdkVersion 16
targetSdkVersion 29
minSdkVersion flutter.minSdkVersion
targetSdkVersion 33
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -38,6 +38,11 @@ android {
signingConfig signingConfigs.debug
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

flutter {
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
android:windowSoftInputMode="adjustResize"
android:exported="true">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
package fr.g123k.flutterappbadge.flutterappbadgerexample;

import android.os.Bundle;

import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
import io.flutter.embedding.android.FlutterActivity;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

Expand Down
3 changes: 2 additions & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Tue Jan 02 14:47:09 CET 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
12 changes: 4 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,13 @@ class _MyAppState extends State<MyApp> {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new Text('Badge supported: $_appBadgeSupported\n'),
new RaisedButton(
new ElevatedButton(
child: new Text('Add badge'),
onPressed: () {
_addBadge();
},
onPressed: () => _addBadge(),
),
new RaisedButton(
new ElevatedButton(
child: new Text('Remove badge'),
onPressed: () {
_removeBadge();
}),
onPressed: () => _removeBadge()),
],
),
),
Expand Down
9 changes: 3 additions & 6 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
name: flutter_app_badger_example
description: Demonstrates how to use the flutter_app_badger plugin.

environment:
sdk: '>=2.12.0 <3.0.0'
environment:
sdk: '>=2.19.6 <4.0.0'
flutter: ">=3.7.12"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down
12 changes: 0 additions & 12 deletions ios/Classes/FlutterAppBadgerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,7 @@ + (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
[registrar addMethodCallDelegate:instance channel:channel];
}

- (void)enableNotifications {
if (@available(iOS 10, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
[center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error){}];
} else {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:[[UIApplication sharedApplication] currentUserNotificationSettings].categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
Comment on lines -17 to -20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure we don't need this?

}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
[self enableNotifications];

if ([@"updateBadgeCount" isEqualToString:call.method]) {
NSDictionary *args = call.arguments;
NSNumber *count = [args objectForKey:@"count"];
Expand Down
10 changes: 5 additions & 5 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: flutter_app_badger
description: Plugin to update the app badge on the launcher (both for Android, iOS and macOS)
version: 1.5.0
version: 1.5.2
homepage: https://github.com/g123k/flutter_app_badger

environment:
sdk: '>=2.19.6 <4.0.0'
flutter: '>=3.7.12'

dependencies:
flutter:
sdk: flutter
Expand All @@ -18,7 +22,3 @@ flutter:
macos:
pluginClass: FlutterAppBadgerPlugin


environment:
sdk: '>=2.12.0 <3.0.0'
flutter: ">=1.10.0"