Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use proper context instead of activity #1232

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions android/src/main/java/com/bleplx/BlePlxModule.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.bleplx;

import android.app.Activity;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -52,9 +50,11 @@
@ReactModule(name = BlePlxModule.NAME)
public class BlePlxModule extends ReactContextBaseJavaModule {
public static final String NAME = "BlePlx";
private final ReactApplicationContext reactContext;

public BlePlxModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
RxJavaPlugins.setErrorHandler(throwable -> {
if (throwable instanceof UndeliverableException) {
RxBleLog.e("Handle all unhandled exceptions from RxJava: " + throwable.getMessage());
Expand Down Expand Up @@ -98,11 +98,7 @@ public Map<String, Object> getConstants() {

@ReactMethod
public void createClient(String restoreStateIdentifier) {
final Activity activity = getCurrentActivity();
if (activity == null) {
return;
}
bleAdapter = BleAdapterFactory.getNewAdapter(activity);
bleAdapter = BleAdapterFactory.getNewAdapter(reactContext);
bleAdapter.createClient(restoreStateIdentifier,
new OnEventCallback<String>() {
@Override
Expand Down
Loading