100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Consoles BLE and notification fixes #1099)
Michael Rademaker53fc18884ace
diff --git a/console/android/ORLib/build.gradle b/console/android/ORLib/build.gradleindex ab671ab16..ddf3a8300 100644--- a/console/android/ORLib/build.gradle+++ b/console/android/ORLib/build.gradle@@ -48,4 +48,5 @@ dependencies {implementation "com.fasterxml.jackson.module:jackson-module-kotlin:2.13.1"implementation platform('com.google.firebase:firebase-bom:32.2.0')implementation 'com.google.firebase:firebase-messaging-ktx'+ implementation 'androidx.constraintlayout:constraintlayout:2.1.4'}diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.ktindex 3a8c72cd5..db1d40652 100644--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORFirebaseMessagingService.kt@@ -17,6 +17,7 @@ import io.openremote.orlib.ORConstantsimport io.openremote.orlib.Rimport io.openremote.orlib.models.ORAlertActionimport io.openremote.orlib.models.ORAlertButton+import io.openremote.orlib.ui.NotificationActivityimport io.openremote.orlib.ui.OrMainActivityimport java.util.logging.Levelimport java.util.logging.Logger@@ -165,8 +166,8 @@ class ORFirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagi) {val pm = packageManagerval notificationIntent = pm.getLaunchIntentForPackage(packageName)- notificationIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)- val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE)+ notificationIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK)+ val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)val notificationBuilder = NotificationCompat.Builder(this,@@ -210,7 +211,10 @@ class ORFirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagiacknowledgement: String?,ORAlertAction: ORAlertAction?): PendingIntent {- val actionIntent = Intent(this, ORMessagingActionService::class.java)+ val actionIntent = when {+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.S ->Intent(this, NotificationActivity::class.java)+ else -> Intent(this, ORMessagingActionService::class.java)+ }actionIntent.putExtra("notificationId", notificationId)actionIntent.putExtra("acknowledgement", acknowledgement)actionIntent.action = System.currentTimeMillis().toString()@@ -221,7 +225,20 @@ class ORFirebaseMessagingService : com.google.firebase.messaging.FirebaseMessagiactionIntent.putExtra("openInBrowser", ORAlertAction.openInBrowser)actionIntent.putExtra("data", ObjectMapper().writeValueAsString(ORAlertAction.data))}- return PendingIntent.getService(this, 0, actionIntent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)+ return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {+ PendingIntent.getActivity(+ this,+ 0,+ actionIntent,+ PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE)+ } else {+ PendingIntent.getService(+ this,+ 0,+ actionIntent,+ PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE+ )+ }}companion object {diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.ktindex e5d778e56..1f5e186eb 100644--- a/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/service/ORMessagingActionService.kt@@ -5,7 +5,9 @@ import android.app.NotificationManagerimport android.content.Intentimport android.content.pm.PackageManagerimport android.net.Uri+import android.os.Buildimport android.text.TextUtils+import io.openremote.orlib.BuildConfigimport io.openremote.orlib.ORConstantsimport io.openremote.orlib.Rimport io.openremote.orlib.ui.OrMainActivity@@ -18,8 +20,10 @@ class ORMessagingActionService : IntentService("org.openremote.android.ORMessagi}override fun onHandleIntent(intent: Intent?) {- val it = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)- this.sendBroadcast(it)+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {+ val it = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)+ this.sendBroadcast(it)+ }val notificationId = intent!!.getLongExtra("notificationId", 0L)val acknowledgement = intent.getStringExtra("acknowledgement")val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManagerdiff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/NotificationActivity.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/NotificationActivity.ktnew file mode 100644index 000000000..e890f43f8--- /dev/null+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/NotificationActivity.kt@@ -0,0 +1,84 @@+package io.openremote.orlib.ui++import android.app.NotificationManager+import android.content.Intent+import android.content.pm.PackageManager+import android.net.Uri+import android.os.Build+import androidx.appcompat.app.AppCompatActivity+import android.os.Bundle+import android.text.TextUtils+import io.openremote.orlib.ORConstants+import io.openremote.orlib.R+import io.openremote.orlib.service.NotificationResource++class NotificationActivity : AppCompatActivity() {+ private var notificationResource: NotificationResource? = null++ override fun onCreate(savedInstanceState: Bundle?) {+ super.onCreate(savedInstanceState)+ setContentView(R.layout.activity_notification)+ notificationResource = NotificationResource(applicationContext)+ }++ override fun onResume() {+ super.onResume()+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {+ val it = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)+ this.sendBroadcast(it)+ }+ val notificationId = intent!!.getLongExtra("notificationId", 0L)+ val acknowledgement = intent.getStringExtra("acknowledgement")+ val manager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager+ manager.cancel(java.lang.Long.hashCode(notificationId))+ val consoleId = getSharedPreferences(+ applicationContext.getString(R.string.app_name),+ MODE_PRIVATE+ ).getString(ORConstants.CONSOLE_ID_KEY, "")+ if (!TextUtils.isEmpty(consoleId)) {+ notificationResource!!.notificationAcknowledged(+ notificationId,+ consoleId,+ acknowledgement+ )+ }+ val appUrl = intent.getStringExtra("appUrl")+ if (!appUrl.isNullOrBlank()) {+ val openInBrowser = intent.getBooleanExtra("openInBrowser", false)+ val silent = intent.getBooleanExtra("silent", false)+ val data = intent.getStringExtra("data")+ var httpMethod = intent.getStringExtra("httpMethod")+ httpMethod = if (TextUtils.isEmpty(httpMethod)) "GET" else httpMethod++ when {+ openInBrowser -> {+ // Don't load the app just send straight to browser+ val i = Intent(Intent.ACTION_VIEW)+ i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)+ i.data = Uri.parse(appUrl)+ startActivity(i)+ }++ silent -> {+ // Do silent HTTP request+ notificationResource!!.executeRequest(httpMethod!!, appUrl, data)+ }++ else -> {+ val pm: PackageManager = packageManager+ val launchIntent: Intent =+ pm.getLaunchIntentForPackage(applicationContext.packageName) ?: Intent(+ applicationContext,+ OrMainActivity::class.java+ )+ launchIntent.addFlags(+ Intent.FLAG_ACTIVITY_NEW_TASK or+ Intent.FLAG_ACTIVITY_SINGLE_TOP+ )+ launchIntent.putExtra("appUrl", appUrl)+ startActivity(launchIntent)+ }+ }+ }+ }+}diff --git a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.ktindex b8c600511..908068c3c 100644--- a/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt+++ b/console/android/ORLib/src/main/java/io/openremote/orlib/ui/OrMainActivity.kt@@ -149,7 +149,9 @@ open class OrMainActivity : Activity() {}}LOG.fine("Loading web view: $url")- loadUrl(url!!)+ if (url != null) {+ loadUrl(url)+ }}}}diff --git a/console/android/ORLib/src/main/res/layout/activity_notification.xml b/console/android/ORLib/src/main/res/layout/activity_notification.xmlnew file mode 100644index 000000000..fc7a8d19f--- /dev/null+++ b/console/android/ORLib/src/main/res/layout/activity_notification.xml@@ -0,0 +1,8 @@+<?xml version="1.0" encoding="utf-8"?>+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"+ xmlns:tools="http://schemas.android.com/tools"+ android:layout_width="match_parent"+ android:layout_height="match_parent"+ tools:context=".ui.NotificationActivity">++</androidx.constraintlayout.widget.ConstraintLayout>diff --git a/console/android/ORLib/src/main/res/values/colors.xml b/console/android/ORLib/src/main/res/values/colors.xmlindex 40309c13a..99835a70f 100644--- a/console/android/ORLib/src/main/res/values/colors.xml+++ b/console/android/ORLib/src/main/res/values/colors.xml@@ -18,4 +18,5 @@<item name="purple" type="color">#ff660092</item><color name="qr_code_reader_square">#FFFFFFFF</color>-</resources>\ No newline at end of file+ <color name="transparent">#00000000</color>+</resources>diff --git a/console/android/ORLib/src/main/res/values/styles.xml b/console/android/ORLib/src/main/res/values/styles.xmlindex b911207b3..9015c6abe 100644--- a/console/android/ORLib/src/main/res/values/styles.xml+++ b/console/android/ORLib/src/main/res/values/styles.xml@@ -7,4 +7,13 @@<item name="colorAccent">@color/light_green</item></style>-</resources>\ No newline at end of file+ <style name="Theme.Transparent" parent="Theme.AppCompat">+ <item name="android:windowIsTranslucent">true</item>+ <item name="android:windowBackground">@android:color/transparent</item>+ <item name="android:windowContentOverlay">@null</item>+ <item name="android:windowNoTitle">true</item>+ <item name="android:windowIsFloating">true</item>+ <item name="android:backgroundDimEnabled">false</item>+ </style>++</resources>