【发布时间】:2021-11-12 09:43:35
【问题描述】:
首先,为了熟悉 Android 的后台任务和前台服务,我实现了一个原生 android 应用。在某些时候,我有一个工作的前台服务通知应用程序 - 很好。
// native Android:
Intent runningIntentService = new Intent(getApplicationContext(), ForegroundService.class);
stopService(runningIntentService);
startService(runningIntentService); // the onCommandStart is being executed.
然后我将所有内容编译为cordova插件,但最终没有调用服务的onCommandStart方法。在科尔多瓦做什么才能启动服务?
// Cordova:
try {
Intent runningIntentService = new Intent(cordova.getActivity().getApplicationContext(), ForegroundService.class);
Log.d("test", "#1"); // gets logged
cordova.getActivity().stopService(runningIntentService);
Log.d("test", "#2"); // gets logged
cordova.getActivity().startService(runningIntentService); // the onCommand is not being executed.
Log.d("test", "#3"); // gets logged
} catch (Exception e) {
Log.e("test","Error: " + e.toString()); // nothing is catched.
}
【问题讨论】:
标签: android cordova cordova-android