离子背景模式 moveToForeground() 不起作用

问题描述

我正在尝试使用 Ionic 和后台模式插件构建一个简单的功能,当应用程序在 N 秒后发送到后台以将应用程序带回前台时。

npm i cordova-plugin-background-mode
npm install @ionic-native/background-mode

app.modules.ts

import { IonicModule,IonicRouteStrategy } from '@ionic/angular';

import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';

import { BackgroundMode } from '@ionic-native/background-mode/ngx';

@NgModule({
  declarations: [AppComponent],entryComponents: [],imports: [browserModule,IonicModule.forRoot(),AppRoutingModule],providers: [BackgroundMode,{ provide: RouteReuseStrategy,useClass: IonicRouteStrategy }],bootstrap: [AppComponent],})
export class AppModule {}

app.component.ts

import { Component } from '@angular/core';
import { BackgroundMode } from '@ionic-native/background-mode/ngx';

@Component({
  selector: 'app-root',templateUrl: 'app.component.html',styleUrls: ['app.component.scss'],})
export class AppComponent {
  constructor(private backgroundMode: BackgroundMode) {
    console.log("application component started");
    let self = this;

    this.backgroundMode.enable();
    this.backgroundMode.on('activate').subscribe(() => {
      setTimeout(function () {
        console.log("set timeout triggered");
        self.backgroundMode.movetoForeground();
      },5000);
    });
  }
}

当我尝试使用 android studio 调试应用程序时

ionic cap open android -l

我可以在应用程序启动时看到 console.log("application component started");输出,也可以在 5 秒后将应用程序置于后台时看到 console.log("set timeout triggered"); 语句的输出

但是下面一行

self.backgroundMode.movetoForeground();

没有效果,应用程序保持在后台

非常感谢任何正确方向的提示

这是 ionic info输出

Ionic:

   Ionic CLI                     : 6.13.1 (/usr/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.5.4
   @angular-devkit/build-angular : 0.1101.4
   @angular-devkit/schematics    : 11.1.4
   @angular/cli                  : 11.1.4
   @ionic/angular-toolkit        : 3.1.0

Capacitor:

   Capacitor CLI   : 2.4.6
   @capacitor/core : 2.4.6

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res : not installed
   native-run  : 1.3.0

System:

   NodeJS : v15.10.0 (/usr/bin/node)
   npm    : 6.14.11
   OS     : Linux 5.11

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...