MaikuB / flutter_local_notifications

A Flutter plugin for displaying local notifications on Android, iOS, macOS and Linux
2.47k stars 1.4k forks source link

Xiaomi notification settings #1626

Closed gdet closed 2 years ago

gdet commented 2 years ago

Hello, I have created successfully the notifications for other devices except xiaomi. I know that this is an issue that is already mentioned but I was wondering how can I fix it by changing app settings. I have already enabled notifications, sound etc from inside application's settings but they are still not working when you delete the application from running in the background. Have I done something wrong or there is no solution to enable the notifications manually?

var androidChannel = AndroidNotificationDetails(
    'PROMPTED_1', 'PROMPTED',
    importance: Importance.max,
    priority: Priority.high,
    playSound: true,
    fullScreenIntent: true,
    showWhen: true,
    timeoutAfter: 4000);

var dateTime900 = DateTime(DateTime.now().year, DateTime.now().month,
    DateTime.now().day, startHour, startMinute, 0);
var platformChannel900 = NotificationDetails(android: androidChannel);

await flutterLocalNotificationsPlugin.zonedSchedule(
  0,
  'Hello!',
  'Press to answer the questionnaire',
  tz.TZDateTime.from(dateTime900, tz.local),
  //RepeatInterval.everyMinute,
  platformChannel900,
  payload: 'New payload',
  androidAllowWhileIdle: true,
  uiLocalNotificationDateInterpretation:
      UILocalNotificationDateInterpretation.absoluteTime,
  matchDateTimeComponents: DateTimeComponents.time,
);

Thank you

gdet commented 2 years ago

Two people have answered my question but for some reason the comments were erased. The solution is to enable autostart and also they added this link https://stackoverflow.com/questions/34149198/how-to-enable-auto-start-for-my-app-in-xiaomi-programmatically

thank you

iqfareez commented 2 years ago

Hi. Yes correct, the Autostart settings is one of the culprits for these notification issues, some Chinese OEMs (Xiaomi, Vivo etc.) put restriction to "save battery life". You can read this article. They basically explain how these OEMs frustrates the developer

While there is no way to enable the Autostart programmatically, you can ask user to enable it. Here what you gonna do: