我试图在android studio中构建我的ionic应用程序,但收到了此错误
2021-07-04 15:58:42.279 11626-11626/com.siloc.users E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.siloc.users, PID: 11626
java.lang.RuntimeException: Unable to start service com.davidbriglio.foreground.ForegroundService@1d25633 with null: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4432)
at android.app.ActivityThread.access$2100(ActivityThread.java:259)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2142)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:230)
at android.app.ActivityThread.main(ActivityThread.java:7880)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getAction()' on a null object reference
at com.davidbriglio.foreground.ForegroundService.onStartCommand(ForegroundService.java:16)
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4414)
at android.app.ActivityThread.access$2100(ActivityThread.java:259)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2142)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:230)
at android.app.ActivityThread.main(ActivityThread.java:7880)
似乎前台服务出了问题,我该如何解决
这是我在应用程序中使用前台服务的方式
import { ForegroundService } from '@ionic-native/foreground-service';
ForegroundService.start('GPS Running', 'Background Service', 'drawable/fsicon');
androidmanifest.xml
<application >
<service android:name="de.appplant.cordova.plugin.background.ForegroundService"/>
<service android:name="com.davidbriglio.foreground.ForegroundService" android:stopWithTask="true"/>
</application>
下面是我使用foregroundservices的main.js文件 main.js
```
import { BackgroundMode } from '@ionic-native/background-mode';
import { ForegroundService } from '@ionic-native/foreground-service';
import { defineCustomElements } from '@ionic/pwa-elements/loader';
import { Plugins } from '@capacitor/core';
import Pusher from "pusher-js";
import StoragePlugin from 'vue-web-storage';
const { App, PushNotifications } = Plugins;
const routerEl = document.querySelector('ion-router');
console.log('Ro', routerEl)
document.addEventListener('ionBackButton', (ev) => {
ev.detail.register(-1, () => {
const path = window.location.pathname;
if (path === routerEl.root) {
App.exitApp();
}
});
});
BackgroundMode.enable();
BackgroundMode.on('activate', () => {
BackgroundMode.disableBatteryOptimizations();
BackgroundMode.disableWebViewOptimizations();
})
ForegroundService.start('GPS Running', 'Background Service', 'drawable/fsicon');
const app = createApp(AppMain)
.use(IonicVue)
.use(router)
.use(RouterPrefetch)
.use(StoragePlugin)
.use(store);
defineCustomElements(window);
router.isReady().then(() => {
app.mount('#app');
});
下面是我使用foregroundservices的main.js文件
暂无答案!
目前还没有任何答案,快来回答吧!