diff --git a/android/app/build.gradle b/android/app/build.gradle
index d946affb..9aadf76f 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -84,4 +84,5 @@ flutter {
dependencies {
implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300'
+ implementation 'com.huawei.hms:push:6.7.0.300'
}
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml
index c1ce832f..13ec16d8 100644
--- a/android/app/src/main/AndroidManifest.xml
+++ b/android/app/src/main/AndroidManifest.xml
@@ -68,5 +68,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/android/app/src/main/java/com/example/test_sa/HService.java b/android/app/src/main/java/com/example/test_sa/HService.java
new file mode 100644
index 00000000..6ff86bab
--- /dev/null
+++ b/android/app/src/main/java/com/example/test_sa/HService.java
@@ -0,0 +1,25 @@
+package com.example.test_sa;
+
+import android.util.Log;
+
+import com.huawei.hms.push.HmsMessageService;
+import com.huawei.hms.push.RemoteMessage;
+
+public class HService extends HmsMessageService {
+
+ @Override
+ public void onMessageReceived(RemoteMessage remoteMessage) {
+ super.onMessageReceived(remoteMessage);
+
+ if (remoteMessage != null) {
+ System.out.println("remote:"+remoteMessage.getData());
+ if (!remoteMessage.getData().isEmpty()) {
+ Log.d("HMS", "Payload" + remoteMessage.getData());
+ }
+
+ if (remoteMessage.getNotification() != null) {
+ Log.d("HMS", "Message Notification Body: " + remoteMessage.getNotification().getBody());
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/lib/controllers/notification/firebase_notification_manger.dart b/lib/controllers/notification/firebase_notification_manger.dart
index 7862cd34..8218f30d 100644
--- a/lib/controllers/notification/firebase_notification_manger.dart
+++ b/lib/controllers/notification/firebase_notification_manger.dart
@@ -7,7 +7,7 @@ import 'package:google_api_availability/google_api_availability.dart';
// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart';
import 'package:huawei_push/huawei_push.dart' as h_push;
import 'package:test_sa/controllers/notification/notification_manger.dart';
-
+import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/models/all_requests_and_count_model.dart';
import 'package:test_sa/models/device/asset_transfer.dart';
import 'package:test_sa/models/new_models/gas_refill_model.dart';
@@ -40,18 +40,11 @@ class FirebaseNotificationManger {
if (!(await isGoogleServicesAvailable())) {
h_push.Push.enableLogger();
final result = await h_push.Push.setAutoInitEnabled(true);
-
- h_push.Push.onNotificationOpenedApp.listen((message) {
- // newMessage(toFirebaseRemoteMessage(message));
- }, onError: (e) => print(e.toString()));
-
- h_push.Push.onMessageReceivedStream.listen((message) {
- // newMessage(toFirebaseRemoteMessage(message));
- }, onError: (e) => print(e.toString()));
+ h_push.Push.onMessageReceivedStream.listen(_onMessageReceived, onError: _onMessageReceiveError);
h_push.Push.getTokenStream.listen((hToken) {
// onToken(token);
- print("Huawei Token: ${token}");
+ // print("Huawei Token: ${hToken}");
token = hToken;
}, onError: (e) {
print(e.toString());
@@ -75,7 +68,15 @@ class FirebaseNotificationManger {
}
}
print("pushToken:$token");
- // return token;
+ // return token;
+ }
+
+ static void _onMessageReceived(h_push.RemoteMessage remoteMessage) {
+ print("onMessageReceivedStream:${remoteMessage.toMap()}");
+ }
+
+ static void _onMessageReceiveError(Object error) {
+ print("onMessageReceivedStream:${error?.toString()}");
}
static Future isGoogleServicesAvailable() async {
@@ -119,7 +120,27 @@ class FirebaseNotificationManger {
}
static initialized(BuildContext context) async {
- //await Firebase.initializeApp();
+ if (!(await isGoogleServicesAvailable())) {
+ var initialNotification = await h_push.Push.getInitialNotification();
+ if (initialNotification != null) {
+ Map remoteData = Map.from(initialNotification["extras"] as Map);
+ handleMessage(context, remoteData);
+ }
+
+ h_push.Push.onNotificationOpenedApp.listen((message) {
+ try {
+ if (message is Map) {
+ Map remoteData = message;
+ remoteData = remoteData["extras"];
+ handleMessage(context, remoteData);
+ }
+ } catch (ex) {
+ print("parsingError:$ex");
+ }
+ }, onError: (e) => print("onNotificationOpenedApp Error${e.toString()}"));
+ return;
+ }
+
NotificationSettings settings;
try {
diff --git a/lib/models/user.dart b/lib/models/user.dart
index 6c525eb2..367c05ec 100644
--- a/lib/models/user.dart
+++ b/lib/models/user.dart
@@ -1,3 +1,5 @@
+import 'dart:io';
+
import 'package:test_sa/controllers/notification/firebase_notification_manger.dart';
import 'package:test_sa/models/enums/user_types.dart';
@@ -73,11 +75,8 @@ class User {
Future