I have been trying to write a module for react-native thats should call a Javascript method when the phone recevies a call. But when i run the command react-native run-android
the compileDebugJavaWithJavac
craches with the following error.
CallListenerModule.java:44 error: package DeviceEventManagerModule does not exist (DeviceEventManagerModule.RCTDeviceEventEmitter.class)
this is the CallListenerModule class:
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import android.util.Log;
public class CallListenerModule extends ReactContextBaseJavaModule {
BroadcastReceiverCustom broadcastRecevier;
ReactContext context;
public CallListenerModule(ReactApplicationContext reactContext) {
super(reactContext);
context = reactContext;
broadcastRecevier = new BroadcastReceiverCustom(reactContext);
}
@Override
public String getName() {
return "CallListenerModule";
}
public void sendCallEvent(String incomingNumber){
WritableMap params = Arguments.createMap();
params.putString("Number", incomingNumber);
sendEvent(context, "CallRecevied", params);
}
private void sendEvent(ReactContext reactContext,
String eventName,
WritableMap params) {
reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
}
}
I have search the great internet for a solution for this problem but with no luck. The sendEvent
method is copied from the docs. I removed the @Nullable
from the params parameter because it casued another error and I do not intend on sending event without a parameter.
This is my first post on SO so any constructive criticism is appreciated :)
You forgot to import the class com.facebook.react.modules.core.DeviceEventManagerModule
. Therefore you can solve your problem by adding the following line:
import com.facebook.react.modules.core.DeviceEventManagerModule
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With