diff --git a/app/src/main/java/com/geeksville/mesh/MainActivity.kt b/app/src/main/java/com/geeksville/mesh/MainActivity.kt index 88960fc47..f9e223ad2 100644 --- a/app/src/main/java/com/geeksville/mesh/MainActivity.kt +++ b/app/src/main/java/com/geeksville/mesh/MainActivity.kt @@ -422,25 +422,6 @@ class MainActivity : AppCompatActivity(), Logging { ) } - private fun unbindMeshService() { - // If we have received the service, and hence registered with - // it, then now is the time to unregister. - // if we never connected, do nothing - debug("Unbinding from mesh service!") - connectionJob?.let { job -> - connectionJob = null - warn("We had a pending onConnection job, so we are cancelling it") - job.cancel("unbinding") - } - mesh.close() - serviceRepository.setMeshService(null) - } - - override fun onStop() { - unbindMeshService() - super.onStop() - } - override fun onStart() { super.onStart() diff --git a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt index 57cae5aaa..376b40bdb 100644 --- a/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt +++ b/app/src/main/java/com/geeksville/mesh/service/MeshServiceNotifications.kt @@ -356,40 +356,37 @@ class MeshServiceNotifications( private fun createOpenMessageIntent(contactKey: String): PendingIntent { val deepLink = "$DEEP_LINK_BASE_URI/messages/$contactKey" - val startActivityIntent = Intent( + val deepLinkIntent = Intent( Intent.ACTION_VIEW, deepLink.toUri(), context, MainActivity::class.java ) - val resultPendingIntent: PendingIntent? = TaskStackBuilder.create(context).run { - addNextIntentWithParentStack(startActivityIntent) - getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE) + val deepLinkPendingIntent: PendingIntent = TaskStackBuilder.create(context).run { + addNextIntentWithParentStack(deepLinkIntent) + getPendingIntent(0, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) } - return resultPendingIntent!! + + return deepLinkPendingIntent } - private fun commonBuilder(channel: String): NotificationCompat.Builder { + private fun commonBuilder( + channel: String, + contentIntent: PendingIntent? = null + ): NotificationCompat.Builder { val builder = NotificationCompat.Builder(context, channel) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setContentIntent(openAppIntent) + .setContentIntent(contentIntent ?: openAppIntent) - // Set the notification icon - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP_MR1) { - // If running on really old versions of android (<= 5.1.1) (possibly only cyanogen) we might encounter a bug with setting application specific icons - // so punt and stay with just the bluetooth icon - see https://meshtastic.discourse.group/t/android-1-1-42-ready-for-alpha-testing/2399/3?u=geeksville - builder.setSmallIcon(android.R.drawable.stat_sys_data_bluetooth) - } else { - builder.setSmallIcon( - // vector form icons don't work reliably on older androids - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { - R.drawable.app_icon_novect - } else { - R.drawable.app_icon - } - ) - } + builder.setSmallIcon( + // vector form icons don't work reliably on older androids + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { + R.drawable.app_icon_novect + } else { + R.drawable.app_icon + } + ) return builder } @@ -435,11 +432,11 @@ class MeshServiceNotifications( message: String ): Notification { if (!::messageNotificationBuilder.isInitialized) { - messageNotificationBuilder = commonBuilder(messageChannelId) + messageNotificationBuilder = + commonBuilder(messageChannelId, createOpenMessageIntent(contactKey)) } val person = Person.Builder().setName(name).build() with(messageNotificationBuilder) { - setContentIntent(createOpenMessageIntent(contactKey)) priority = NotificationCompat.PRIORITY_DEFAULT setCategory(Notification.CATEGORY_MESSAGE) setAutoCancel(true)