Skip to content

Commit

Permalink
Android 14 exporting flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aritchie committed Dec 2, 2023
1 parent b4fbdbc commit fc95e4b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Shiny.BluetoothLE/Platforms/Android/BleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ await this.services
};

this.platform.RegisterBroadcastReceiver<ShinyBleBroadcastReceiver>(
true,
BluetoothDevice.ActionNameChanged,
BluetoothDevice.ActionBondStateChanged,
BluetoothDevice.ActionPairingRequest,
Expand Down Expand Up @@ -152,6 +153,7 @@ await this.services
};

this.platform.RegisterBroadcastReceiver<ShinyBleAdapterStateBroadcastReceiver>(
true,
BluetoothAdapter.ActionStateChanged,
Intent.ActionBootCompleted
);
Expand Down
15 changes: 14 additions & 1 deletion src/Shiny.Core/Platforms/Android/AndroidPlatform.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,26 @@ public T GetSystemService<T>(string key) where T : Java.Lang.Object
=> (T)this.AppContext.GetSystemService(key);


public void RegisterBroadcastReceiver<T>(params string[] actions) where T : BroadcastReceiver, new()
public void RegisterBroadcastReceiver<T>(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
}


Expand Down

0 comments on commit fc95e4b

Please sign in to comment.