Skip to content

Commit

Permalink
Notification Issue cause android 13 stuck at startup
Browse files Browse the repository at this point in the history
  • Loading branch information
7Eltantawy committed Dec 13, 2022
1 parent ba0326a commit 7fecf66
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 75 deletions.
4 changes: 2 additions & 2 deletions hisnelmoslem/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ if (keystorePropertiesFile.exists()) {
}

android {
compileSdkVersion 32
compileSdkVersion 33

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -41,7 +41,7 @@ android {
defaultConfig {
applicationId "com.hassaneltantawy.hisnelmoslem"
minSdkVersion 21
targetSdkVersion 32
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
17 changes: 11 additions & 6 deletions hisnelmoslem/lib/app/init_services.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import 'package:get_storage/get_storage.dart';
import 'package:hisnelmoslem/app/shared/functions/print.dart';
import 'package:hisnelmoslem/core/utils/alarm_manager.dart';
import 'package:hisnelmoslem/core/utils/awesome_notification_manager.dart';
import 'package:hisnelmoslem/core/utils/migration/migration.dart';
import 'package:hisnelmoslem/core/utils/notification_manager.dart';

Future<void> initServices() async {
await GetStorage.init();
await Migration.start();
await awesomeNotificationManager.init();
await localNotifyManager.cancelAllNotifications();
await awesomeNotificationManager.appOpenNotification();
await alarmManager.checkAllAlarmsInDb();
try {
await GetStorage.init();
await Migration.start();
await awesomeNotificationManager.init();
await alarmManager.checkAllAlarmsInDb();
await localNotifyManager.cancelAllNotifications();
await awesomeNotificationManager.appOpenNotification();
} catch (e) {
hisnPrint(e);
}
}
142 changes: 75 additions & 67 deletions hisnelmoslem/lib/core/utils/awesome_notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,79 +16,87 @@ AwesomeNotificationManager awesomeNotificationManager =

class AwesomeNotificationManager {
Future<void> checkIfAllowed(BuildContext context) async {
await AwesomeNotifications().isNotificationAllowed().then(
(isAllowed) {
if (!isAllowed) {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
title: Text("Allow app to send notifications?".tr),
content: Text(
"Hisn ELmoslem need notification permission to send zikr reminders."
.tr),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(
"Later".tr,
style: const TextStyle(color: Colors.grey, fontSize: 18),
try {
await AwesomeNotifications().isNotificationAllowed().then(
(isAllowed) {
if (!isAllowed) {
showDialog(
context: context,
builder: (context) => AlertDialog(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20))),
title: Text("Allow app to send notifications?".tr),
content: Text(
"Hisn ELmoslem need notification permission to send zikr reminders."
.tr),
actions: [
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: Text(
"Later".tr,
style: const TextStyle(color: Colors.grey, fontSize: 18),
),
),
),
TextButton(
onPressed: () => AwesomeNotifications()
.requestPermissionToSendNotifications()
.then((_) => Navigator.pop(context)),
child: Text(
"Allow".tr,
style: const TextStyle(
color: Colors.teal,
fontSize: 18,
fontWeight: FontWeight.bold,
TextButton(
onPressed: () => AwesomeNotifications()
.requestPermissionToSendNotifications()
.then((_) => Navigator.pop(context)),
child: Text(
"Allow".tr,
style: const TextStyle(
color: Colors.teal,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
);
}
},
);
],
),
);
}
},
);
} catch (e) {
hisnPrint(e);
}
}

Future<void> init() async {
await AwesomeNotifications().initialize(
/// using null here mean it will use app icon for notification icon
/// If u want use custom one replace null with below
/// 'resource://drawable/res_app_icon',
null,
[
NotificationChannel(
channelKey: 'in_app_notification',
channelName: 'In App Notification',
channelDescription: 'For internal notifications',
defaultColor: Colors.teal,
importance: NotificationImportance.High,
channelShowBadge: true,
enableLights: true,
playSound: true,
),
NotificationChannel(
channelKey: 'scheduled_channel',
channelName: 'Scheduled Notifications',
channelDescription: 'For Scheduled notifications',
defaultColor: Colors.teal,
importance: NotificationImportance.High,
locked: true,
channelShowBadge: true,
playSound: true,
),
],
debug: true,
);
try {
await AwesomeNotifications().initialize(
/// using null here mean it will use app icon for notification icon
/// If u want use custom one replace null with below
/// 'resource://drawable/res_app_icon',
null,
[
NotificationChannel(
channelKey: 'in_app_notification',
channelName: 'In App Notification',
channelDescription: 'For internal notifications',
defaultColor: Colors.teal,
importance: NotificationImportance.High,
channelShowBadge: true,
enableLights: true,
playSound: true,
),
NotificationChannel(
channelKey: 'scheduled_channel',
channelName: 'Scheduled Notifications',
channelDescription: 'For Scheduled notifications',
defaultColor: Colors.teal,
importance: NotificationImportance.High,
locked: true,
channelShowBadge: true,
playSound: true,
),
],
debug: true,
);
} catch (e) {
hisnPrint(e);
}
}

void listen() {
Expand Down

0 comments on commit 7fecf66

Please sign in to comment.