Skip to content

Commit

Permalink
Fix @ledgerhq/react-native-hid for android sdk34
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-meilan committed Sep 27, 2024
1 parent 5707a08 commit a27a8e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .changeset/three-lions-smoke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/react-native-hid": patch
---

Android sdk 34 give the following error when use transporter from the lib @ledger/react-native-hid:

One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts.

To fix this bug is needed call getReactApplicationContext() with the Context.RECEIVER_NOT_EXPORTED attribute. https://github.com/LedgerHQ/ledger-live/issues/7786
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.os.Build;

import androidx.annotation.NonNull;

Expand Down Expand Up @@ -58,6 +59,11 @@ public void onReceive(Context context, Intent intent) {
.emit(event, buildMapFromDevice(device));
}
};
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getReactApplicationContext().registerReceiver(receiver, filter, Context.RECEIVER_NOT_EXPORTED);
return;
}

getReactApplicationContext().registerReceiver(receiver, filter);
}

Expand Down Expand Up @@ -213,7 +219,12 @@ public void onReceive(Context context, Intent intent) {
unregisterReceiver(this);
}
};
getReactApplicationContext().registerReceiver(receiver, intFilter);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
getReactApplicationContext().registerReceiver(receiver, intFilter, Context.RECEIVER_NOT_EXPORTED);
return;
}

getReactApplicationContext().registerReceiver(receiver, intFilter, Context.RECEIVER_NOT_EXPORTED);
}

private void unregisterReceiver(BroadcastReceiver receiver) {
Expand Down

0 comments on commit a27a8e3

Please sign in to comment.