@@ -27,7 +27,16 @@ public static Task<bool> RequestPermissionAsync(this UsbManager manager, UsbDevi
2727 var completionSource = new TaskCompletionSource < bool > ( ) ;
2828
2929 var usbPermissionReceiver = new UsbPermissionReceiver ( completionSource ) ;
30- context . RegisterReceiver ( usbPermissionReceiver , new IntentFilter ( ACTION_USB_PERMISSION ) ) ;
30+ if ( Build . VERSION . SdkInt >= BuildVersionCodes . Tiramisu )
31+ {
32+ #pragma warning disable CA1416
33+ context . RegisterReceiver ( usbPermissionReceiver , new IntentFilter ( ACTION_USB_PERMISSION ) , ReceiverFlags . NotExported ) ;
34+ #pragma warning restore CA1416
35+ }
36+ else
37+ {
38+ context . RegisterReceiver ( usbPermissionReceiver , new IntentFilter ( ACTION_USB_PERMISSION ) ) ;
39+ }
3140
3241 // Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
3342#if NET6_0_OR_GREATER
@@ -36,9 +45,14 @@ public static Task<bool> RequestPermissionAsync(this UsbManager manager, UsbDevi
3645 PendingIntentFlags pendingIntentFlags = Build . VERSION . SdkInt >= ( BuildVersionCodes ) 31 ? ( PendingIntentFlags ) .33554432 : 0 ;
3746#endif
3847
39- var intent = PendingIntent . GetBroadcast ( context , 0 , new Intent ( ACTION_USB_PERMISSION ) , pendingIntentFlags ) ;
48+ var intent = new Intent ( ACTION_USB_PERMISSION ) ;
49+ if ( Build . VERSION . SdkInt >= BuildVersionCodes . UpsideDownCake )
50+ {
51+ intent . SetPackage ( context . PackageName ) ;
52+ }
53+ var pendingIntent = PendingIntent . GetBroadcast ( context , 0 , intent , pendingIntentFlags ) ;
4054
41- manager . RequestPermission ( device , intent ) ;
55+ manager . RequestPermission ( device , pendingIntent ) ;
4256
4357 return completionSource . Task ;
4458 }
0 commit comments