Skip to content

Commit

Permalink
[flutter_local_notifications] use type safer intent APIs on Android A…
Browse files Browse the repository at this point in the history
…PI 33+ (MaikuB#1705)

* fix android deprecation warnings around intent APIs

* Google Java Format

* add suppress warnings annotation

Co-authored-by: github-actions <>
  • Loading branch information
MaikuB authored Sep 17, 2022
1 parent 0144fa6 commit cc9f2f8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@
public class ForegroundService extends Service {

@Override
@SuppressWarnings("deprecation")
public int onStartCommand(Intent intent, int flags, int startId) {
ForegroundServiceStartParameter parameter =
(ForegroundServiceStartParameter)
intent.getSerializableExtra(ForegroundServiceStartParameter.EXTRA);
ForegroundServiceStartParameter parameter;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
parameter =
(ForegroundServiceStartParameter)
intent.getSerializableExtra(
ForegroundServiceStartParameter.EXTRA, ForegroundServiceStartParameter.class);
} else {
parameter =
(ForegroundServiceStartParameter)
intent.getSerializableExtra(ForegroundServiceStartParameter.EXTRA);
}

Notification notification =
FlutterLocalNotificationsPlugin.createNotification(this, parameter.notificationData);
if (parameter.foregroundServiceTypes != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Keep
public class ScheduledNotificationBootReceiver extends BroadcastReceiver {
@Override
@SuppressWarnings("deprecation")
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if (action != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ public void onReceive(final Context context, Intent intent) {
intent.getStringExtra(FlutterLocalNotificationsPlugin.NOTIFICATION_DETAILS);
if (StringUtils.isNullOrEmpty(notificationDetailsJson)) {
// This logic is needed for apps that used the plugin prior to 0.3.4
Notification notification = intent.getParcelableExtra("notification");
Notification notification;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.TIRAMISU) {
notification = intent.getParcelableExtra("notification", Notification.class);
} else {
notification = intent.getParcelableExtra("notification");
}
notification.when = System.currentTimeMillis();
int notificationId = intent.getIntExtra("notification_id", 0);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

#include "generated_plugin_registrant.h"

#include <url_launcher_linux/url_launcher_plugin.h>

void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
url_launcher_linux
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ import flutter_local_notifications
import flutter_native_timezone
import path_provider_macos
import shared_preferences_macos
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin"))
FlutterNativeTimezonePlugin.register(with: registry.registrar(forPlugin: "FlutterNativeTimezonePlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}

0 comments on commit cc9f2f8

Please sign in to comment.