diff --git a/agconnect-services.json b/agconnect-services.json new file mode 100644 index 00000000..fdcb33d4 --- /dev/null +++ b/agconnect-services.json @@ -0,0 +1,57 @@ +{ + "agcgw_all":{ + "CN":"connect-drcn.dbankcloud.cn", + "CN_back":"connect-drcn.hispace.hicloud.com", + "DE":"connect-dre.dbankcloud.cn", + "DE_back":"connect-dre.hispace.hicloud.com", + "RU":"connect-drru.hispace.dbankcloud.ru", + "RU_back":"connect-drru.hispace.dbankcloud.cn", + "SG":"connect-dra.dbankcloud.cn", + "SG_back":"connect-dra.hispace.hicloud.com" + }, + "websocketgw_all":{ + "CN":"connect-ws-drcn.hispace.dbankcloud.cn", + "CN_back":"connect-ws-drcn.hispace.dbankcloud.com", + "DE":"connect-ws-dre.hispace.dbankcloud.cn", + "DE_back":"connect-ws-dre.hispace.dbankcloud.com", + "RU":"connect-ws-drru.hispace.dbankcloud.ru", + "RU_back":"connect-ws-drru.hispace.dbankcloud.cn", + "SG":"connect-ws-dra.hispace.dbankcloud.cn", + "SG_back":"connect-ws-dra.hispace.dbankcloud.com" + }, + "client":{ + "cp_id":"2640966000002322881", + "product_id":"388421841222408054", + "client_id":"1492841575221308864", + "client_secret":"9F5ABC6C041C90D9CFC2DB4B032E224026C566D30147D22CC25789DAFF393B14", + "project_id":"388421841222408054", + "app_id":"111820283", + "api_key":"DQEDACmCXaRhehJz6Col9ZoLjfEmJCZn2/FIsIDJccmzQmq61gFYr7msISoMMgprtwaxo5vZ4Gyn2TIj6Y7v+sd1IGqforIJaKyaPA==", + "package_name":"com.hmg.atoms" + }, + "oauth_client":{ + "client_id":"111820283", + "client_type":1 + }, + "app_info":{ + "app_id":"111820283", + "package_name":"com.hmg.atoms" + }, + "configuration_version":"3.0", + "appInfos":[ + { + "package_name":"com.hmg.atoms", + "client":{ + "app_id":"111820283" + }, + "app_info":{ + "package_name":"com.hmg.atoms", + "app_id":"111820283" + }, + "oauth_client":{ + "client_type":1, + "client_id":"111820283" + } + } + ] +} \ No newline at end of file diff --git a/android/app/build.gradle b/android/app/build.gradle index ca56c586..d946affb 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -24,6 +24,7 @@ if (flutterVersionName == null) { apply plugin: 'com.android.application' apply plugin: 'kotlin-android' apply plugin: 'com.google.gms.google-services' +apply plugin: 'com.huawei.agconnect' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" def keystoreProperties = new Properties() @@ -63,7 +64,7 @@ android { } buildTypes { debug { - signingConfig signingConfigs.debug + signingConfig signingConfigs.release } // release { // signingConfig signingConfigs.debug @@ -72,6 +73,7 @@ android { minifyEnabled true shrinkResources true signingConfig signingConfigs.release + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } @@ -79,3 +81,7 @@ android { flutter { source '../..' } + +dependencies { + implementation 'com.huawei.agconnect:agconnect-core:1.5.2.300' +} diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro index 6f22e90b..27acb9d8 100644 --- a/android/app/proguard-rules.pro +++ b/android/app/proguard-rules.pro @@ -17,6 +17,17 @@ -keep class * implements com.google.gson.JsonSerializer -keep class * implements com.google.gson.JsonDeserializer +-ignorewarnings +-keepattributes *Annotation* +-keepattributes Exceptions +-keepattributes InnerClasses +-keepattributes Signature +-keepattributes SourceFile,LineNumberTable +-keep class com.huawei.hianalytics.**{*;} +-keep class com.huawei.updatesdk.**{*;} +-keep class com.huawei.hms.**{*;} +-keep class com.huawei.hms.flutter.** { *; } + # Prevent R8 from leaving Data object members always null -keepclassmembers,allowobfuscation class * { @com.google.gson.annotations.SerializedName ; diff --git a/android/build.gradle b/android/build.gradle index 419b3fd3..bf39e77f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -3,12 +3,14 @@ buildscript { repositories { google() mavenCentral() + maven {url 'https://developer.huawei.com/repo/'} } dependencies { classpath 'com.android.tools.build:gradle:7.1.2' classpath 'com.google.gms:google-services:4.3.13' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.huawei.agconnect:agcp:1.5.2.300' } } @@ -16,6 +18,7 @@ allprojects { repositories { google() mavenCentral() + maven {url 'https://developer.huawei.com/repo/'} } } diff --git a/lib/controllers/notification/firebase_notification_manger.dart b/lib/controllers/notification/firebase_notification_manger.dart index fbae40d4..608d0128 100644 --- a/lib/controllers/notification/firebase_notification_manger.dart +++ b/lib/controllers/notification/firebase_notification_manger.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:firebase_messaging/firebase_messaging.dart'; import 'package:flutter/material.dart'; +import 'package:google_api_availability/google_api_availability.dart'; import 'package:test_sa/controllers/notification/notification_manger.dart'; import 'package:test_sa/models/all_requests_and_count_model.dart'; import 'package:test_sa/models/device/asset_transfer.dart'; @@ -13,6 +14,9 @@ import 'package:test_sa/views/pages/user/gas_refill/gas_refill_details.dart'; import 'package:test_sa/views/pages/user/ppm/ppm_details_page.dart'; import 'package:test_sa/views/pages/user/requests/service_request_details.dart'; +// import 'package:huawei_hmsavailability/huawei_hmsavailability.dart'; +import 'package:huawei_push/huawei_push.dart' as h_push; + @pragma('vm:entry-point') Future firebaseMessagingBackgroundHandler(RemoteMessage message) async {} @@ -31,15 +35,60 @@ class FirebaseNotificationManger { sound: true, ); - if (settings.authorizationStatus == AuthorizationStatus.authorized) { + if (Platform.isAndroid) { try { - token = await messaging.getToken(); - } catch (ex) {} + 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.getTokenStream.listen((token) { + // onToken(token); + print("Huawei Token: ${token}"); + FirebaseNotificationManger.token = token; + }, onError: (e) { + print(e.toString()); + } + ); + h_push.Push.getToken(''); + + } else { + if (settings.authorizationStatus == AuthorizationStatus.authorized) { + try { + token = await messaging.getToken(); + } catch (ex) {} + } + } + } catch (ex) { + print("Notification Exception: " + ex.toString()); + } + } else { + if (settings.authorizationStatus == AuthorizationStatus.authorized) { + try { + token = await messaging.getToken(); + } catch (ex) {} + } } print("pushToken:$token"); return token; } + static Future isGoogleServicesAvailable() async { + GooglePlayServicesAvailability availability = await GoogleApiAvailability.instance.checkGooglePlayServicesAvailability(); + String status = availability.toString().split('.').last; + if (status == "success") { + return true; + } + return false; + } + static void handleMessage(context, Map messageData) { if (messageData["requestType"] != null && messageData["requestNumber"] != null) { Widget serviceClass; diff --git a/pubspec.yaml b/pubspec.yaml index c8ea53d4..6ac7d40a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -78,6 +78,8 @@ dependencies: flutter_month_picker: ^0.0.2 syncfusion_flutter_charts: ^21.2.3 local_auth: ^2.1.6 + google_api_availability: ^5.0.0 + huawei_push: ^6.5.0+300 dev_dependencies: flutter_test: