react-native - React Native Headless js,Module AppRegistry 未注册(调用startHeadlessTask)
问题描述
我有反应原生后台服务问题 - Headless JS
我正在使用Expo框架
Android Studio 错误信息:
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" />
我不知道为什么会出现“Module AppRegistry 不是注册的可调用模块(调用 startHeadlessTask)”!?
解决方案
推荐阅读
- r - 为什么不只有一个统一的 `scale_fill` 函数?
- python - Airflow PythonOperator 任务无论如何都不会失败
- javascript - javascript / css动画
- android - 将对象从 Activity 传递到 Main Activity
- pandas - 如何“取消稀疏”数据框
- rest - 远程配置 FreeRADIUS 服务器的最佳方式?
- c++ - 函数指针的全局数组
- npm - 用 npm 安装 expo-cli 给我错误
- node.js - 我们的团队在尝试使用 Heroku CLI 部署到生产环境时遇到错误
- javascript - 在 Nodejs 和 Vuejs 中显示保存在文件夹中的图像和数据库中的名称