Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Push is working!(on Android)

Michael Rademakercbdfe2db56be
diff --git a/console/generic_app/android/app/src/main/AndroidManifest.xml b/console/generic_app/android/app/src/main/AndroidManifest.xml
index 989aeb26f..6d8e454ea 100644
--- a/console/generic_app/android/app/src/main/AndroidManifest.xml
+++ b/console/generic_app/android/app/src/main/AndroidManifest.xml
@@ -43,6 +43,10 @@
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/notification_channel_id" />
+ <meta-data
+ android:name="com.google.firebase.messaging.default_notification_icon"
+ android:resource="@drawable/or_push_icon" />
+
<receiver android:name="io.flutter.plugins.geofencing.GeofencingBroadcastReceiver"
android:enabled="true" android:exported="true"/>
<service android:name="io.flutter.plugins.geofencing.GeofencingService"
diff --git a/console/generic_app/android/app/src/main/kotlin/io/openremote/generic_app/MainActivity.kt b/console/generic_app/android/app/src/main/kotlin/io/openremote/generic_app/MainActivity.kt
index 5f9b2c30d..542af24e2 100644
--- a/console/generic_app/android/app/src/main/kotlin/io/openremote/generic_app/MainActivity.kt
+++ b/console/generic_app/android/app/src/main/kotlin/io/openremote/generic_app/MainActivity.kt
@@ -1,28 +1,7 @@
package io.openremote.generic_app
-import androidx.annotation.NonNull;
-import android.content.Context
-import android.content.Intent
import io.flutter.embedding.android.FlutterActivity
-import io.flutter.embedding.engine.FlutterEngine
-import io.flutter.plugins.GeneratedPluginRegistrant
class MainActivity: FlutterActivity() {
- override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
- GeneratedPluginRegistrant.registerWith(flutterEngine);
- }
-// override fun onDestroy() {
-// flutterEngine?.platformViewsController?.onFlutterViewDestroyed()
-// super.onDestroy()
-// }
-
-// companion object {
-// fun createIntent(context: Context, initialRoute: String = "/"): Intent {
-// return Intent(context, MainActivity::class.java)
-// .putExtra("initial_route", initialRoute)
-// .putExtra("background_mode", "opaque")
-// .putExtra("destroy_engine_with_activity", true)
-// }
-// }
}
diff --git a/console/generic_app/android/app/src/main/res/drawable/or_push_icon.png b/console/generic_app/android/app/src/main/res/drawable/or_push_icon.png
new file mode 100644
index 000000000..e1020884e
Binary files /dev/null and b/console/generic_app/android/app/src/main/res/drawable/or_push_icon.png differ
diff --git a/console/generic_app/assets/images/or_push_icon.png b/console/generic_app/assets/images/or_push_icon.png
new file mode 100644
index 000000000..e1020884e
Binary files /dev/null and b/console/generic_app/assets/images/or_push_icon.png differ
diff --git a/console/generic_app/lib/services/PushNotificationService.dart b/console/generic_app/lib/services/PushNotificationService.dart
index 6069815cd..2c4868bd8 100644
--- a/console/generic_app/lib/services/PushNotificationService.dart
+++ b/console/generic_app/lib/services/PushNotificationService.dart
@@ -13,6 +13,30 @@ import 'package:url_launcher/url_launcher.dart';
import 'EventBusService.dart';
+Future<dynamic> backgroundMessageHandler(Map<String, dynamic> remoteMessage) async {
+ print("background: $remoteMessage");
+ Map<dynamic, dynamic> messageData = remoteMessage["data"] ?? remoteMessage;
+
+ bool isSilent = !messageData.containsKey("or-title");
+
+ if (isSilent) {
+ String action = messageData["action"];
+
+ switch (action) {
+ case "GEOFENCE_REFRESH":
+ GeofenceProvider geofenceProvider = await GeofenceProvider
+ .getInstance();
+ geofenceProvider.refreshGeofences();
+ break;
+ case "STORE":
+ StorageProvider storageProvider = await StorageProvider
+ .getInstance();
+ storageProvider.store(messageData["key"], messageData["value"]);
+ break;
+ }
+ }
+}
+
class PushNotificationService {
static FirebaseMessaging _fcm;
@@ -35,12 +59,10 @@ class PushNotificationService {
print("onResume: $remoteMessage");
await handleNotification(remoteMessage, true, false);
},
- onBackgroundMessage: Platform.isIOS ? null : handleBackgroundNotification,
+ onBackgroundMessage: Platform.isIOS ? null : backgroundMessageHandler,
);
}
- static Future handleBackgroundNotification(Map<String, dynamic> remoteMessage) => handleNotification(remoteMessage, true, true);
-
static Future handleNotification(
Map<String, dynamic> remoteMessage, bool onResume, bool onLaunch) async {
Map<dynamic, dynamic> messageData = remoteMessage["data"] ?? remoteMessage;