From fc95e4b24daf3fda541b0f88591a48c9c5ca9166 Mon Sep 17 00:00:00 2001 From: Allan Ritchie Date: Sat, 2 Dec 2023 11:40:26 -0500 Subject: [PATCH] Android 14 exporting flags --- .../Platforms/Android/BleManager.cs | 2 ++ .../Android/AndroidPlatform.Extensions.cs | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Shiny.BluetoothLE/Platforms/Android/BleManager.cs b/src/Shiny.BluetoothLE/Platforms/Android/BleManager.cs index 98f06732f..f27efd417 100644 --- a/src/Shiny.BluetoothLE/Platforms/Android/BleManager.cs +++ b/src/Shiny.BluetoothLE/Platforms/Android/BleManager.cs @@ -124,6 +124,7 @@ await this.services }; this.platform.RegisterBroadcastReceiver( + true, BluetoothDevice.ActionNameChanged, BluetoothDevice.ActionBondStateChanged, BluetoothDevice.ActionPairingRequest, @@ -152,6 +153,7 @@ await this.services }; this.platform.RegisterBroadcastReceiver( + true, BluetoothAdapter.ActionStateChanged, Intent.ActionBootCompleted ); diff --git a/src/Shiny.Core/Platforms/Android/AndroidPlatform.Extensions.cs b/src/Shiny.Core/Platforms/Android/AndroidPlatform.Extensions.cs index 72288a832..1e84bcf4c 100644 --- a/src/Shiny.Core/Platforms/Android/AndroidPlatform.Extensions.cs +++ b/src/Shiny.Core/Platforms/Android/AndroidPlatform.Extensions.cs @@ -68,13 +68,26 @@ public T GetSystemService(string key) where T : Java.Lang.Object => (T)this.AppContext.GetSystemService(key); - public void RegisterBroadcastReceiver(params string[] actions) where T : BroadcastReceiver, new() + public void RegisterBroadcastReceiver(bool exported, params string[] actions) where T : BroadcastReceiver, new() { + var receiver = new T(); var filter = new IntentFilter(); foreach (var e in actions) filter.AddAction(e); +#if ANDROID34_0_OR_GREATER + if (OperatingSystemShim.IsAndroidVersionAtLeast(34)) + { + var flags = exported ? ReceiverFlags.Exported : ReceiverFlags.NotExported; + this.AppContext.RegisterReceiver(receiver, filter, flags); + } + else + { + this.AppContext.RegisterReceiver(new T(), filter); + } +#else this.AppContext.RegisterReceiver(new T(), filter); +#endif }