应用程式锁定时,DeviceEvenEmitter无法运作

时间:2018-12-11 04:29:07

标签: java reactjs native deviceeventemitter

我有一个React Native App,我从Expo弹出到ExpoKit。在本机模块中,我尝试发出事件:

public void onHostPause() {
    unregisterVolumeReceiver();

    KeyguardManager myKM = (KeyguardManager) mContext.getSystemService(Context.KEYGUARD_SERVICE);
    System.out.println('g');

    if(myKM.inKeyguardRestrictedInputMode()) {

        try {
            WritableMap params = Arguments.createMap(); // add here the data you want to send
            params.putString("event", "locked"); // <- example
            getReactApplicationContext()
                    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                    .emit("locked", params);
        } catch (Exception e){
            System.out.println(e);
        }
    }

}

在我的App.js中,我有:

import { DeviceEventEmitter } from 'react-native';

componentDidMount() {

    DeviceEventEmitter.addListener('locked', () => {
    console.log('locked emitted');
}

}

我的目标是告诉我应用程序的React端何时按下了Lock键,但是到目前为止,DeviceEventEmitter.addListener尚未捕获所发出的事件。有任何想法吗?

0 个答案:

没有答案