huawei push notifications integrated.

main_design2.1
Sikander Saleem 1 year ago
parent 94b591b23d
commit c00e09fddd

@ -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'
}

@ -68,5 +68,40 @@
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_name" />
<meta-data
android:name="push_kit_auto_init_enabled"
android:value="true" />
<!-- These receivers are for sending scheduled local notifications -->
<receiver
android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationBootEventReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
<receiver
android:name="com.huawei.hms.flutter.push.receiver.local.HmsLocalNotificationScheduledPublisher"
android:exported="false" />
<receiver
android:name="com.huawei.hms.flutter.push.receiver.BackgroundMessageBroadcastReceiver"
android:enabled="true"
android:exported="false">
<intent-filter>
<action android:name="com.huawei.hms.flutter.push.receiver.BACKGROUND_REMOTE_MESSAGE" />
</intent-filter>
</receiver>
<!-- <service-->
<!-- android:name=".HService"-->
<!-- android:enabled="true"-->
<!-- android:exported="true"-->
<!-- android:permission="${applicationId}.permission.PROCESS_PUSH_MSG"-->
<!-- android:process=":HmsMessageService">-->
<!-- <intent-filter>-->
<!-- <action android:name="com.huawei.push.action.MESSAGING_EVENT" />-->
<!-- </intent-filter>-->
<!-- </service>-->
</application>
</manifest>

@ -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());
}
}
}
}

@ -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<bool> 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<String, dynamic> remoteData = Map<String, dynamic>.from(initialNotification["extras"] as Map);
handleMessage(context, remoteData);
}
h_push.Push.onNotificationOpenedApp.listen((message) {
try {
if (message is Map<String, dynamic>) {
Map<String, dynamic> remoteData = message;
remoteData = remoteData["extras"];
handleMessage(context, remoteData);
}
} catch (ex) {
print("parsingError:$ex");
}
}, onError: (e) => print("onNotificationOpenedApp Error${e.toString()}"));
return;
}
NotificationSettings settings;
try {

@ -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<Map<String, dynamic>> toLoginJson() async {
// if (FirebaseNotificationManger.token == null) await FirebaseNotificationManger.getToken();
// print("PuToken:${FirebaseNotificationManger?.token}");
return {
"username": userName,
"password": password,
"fireBaseToken": FirebaseNotificationManger?.token ?? "",
};
String notificationType = (Platform.isAndroid && !(await FirebaseNotificationManger.isGoogleServicesAvailable())) ? "HMC" : "FCM";
return {"username": userName, "password": password, "fireBaseToken": FirebaseNotificationManger?.token ?? "", "notificationType": notificationType};
}
UsersTypes get type {

@ -593,10 +593,10 @@ packages:
dependency: "direct main"
description:
name: huawei_push
sha256: "30b4dcab270d81e2c58624e044707886c487d6cb80287db9be629d894e439e40"
sha256: "94c70987591442e301745e881ee2768ca5349800294bb7bdd46f9f80d1096c53"
url: "https://pub.dev"
source: hosted
version: "6.12.0+301"
version: "6.12.0+302"
image:
dependency: transitive
description:

@ -79,7 +79,7 @@ dependencies:
syncfusion_flutter_charts: ^21.2.3
local_auth: ^2.1.6
google_api_availability: ^5.0.0
huawei_push: ^6.5.0+300
huawei_push: ^6.12.0+302
dev_dependencies:
flutter_test:

Loading…
Cancel
Save