React Native Headless js,Module AppRegistry不是注册的(调用startHeadlessTask)

时间:2018-05-10 01:27:43

标签: react-native expo

我正在回应原生后台服务问题 - Headless JS

我正在使用Expo框架

Android Studio错误MSG:

E/ReactNativeJS: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: The Expo SDK requires Expo to run. It appears the native Expo modules are unavailable and this code is not running on Expo. Visit https://docs.expo.io to learn more about developing an Expo project.
E/ReactNativeJS: Module AppRegistry is not a registered callable module (calling startHeadlessTask) 
E/unknown:ReactNative: Unable to launch redbox because react activity is not available, here is the error that redbox would've displayed: Module AppRegistry is not a registered callable module (calling startHeadlessTask)

JS API:(App.js)

const LockScreenOpenService = async (taskData) => {
   DeviceEventEmitter.addListener('LockScreenOpen', function(e: Event) {
      // handle event.
      console.log("== Debug: Received LockScreen View Open");
   });
};

AppRegistry.registerHeadlessTask('LockScreenOpenService', () => 
LockScreenOpenService);

LockScreenOpenService.java:

public class LockScreenOpenService extends HeadlessJsTaskService {

@Override
protected @Nullable
HeadlessJsTaskConfig getTaskConfig(Intent intent) {
    Bundle extras = intent.getExtras();
    if (extras != null) {
        return new HeadlessJsTaskConfig(
                "LockScreenOpenService",
                Arguments.fromBundle(extras),
                5000, // timeout for the task
                false // optional: defines whether or not  the task is allowed in foreground. Default is false
        );
    }
    return null;
}
}

服务开始:

 public void startLockViewService(){
  Intent listenIntent = new Intent(getApplication(), LockScreenOpenService.class);
  Bundle bundle = new Bundle();

  listenIntent.putExtras(bundle);
  startService(listenIntent);
}

的AndroidManifest.xml

    <service
    android:name=".lockscreen.LockScreenOpenService"
    android:enabled="true"
    android:exported="true" />

我不知道为什么&#39; Module AppRegistry不是注册的可调用模块(调用startHeadlessTask)&#39;发生!?

0 个答案:

没有答案