有没有办法通过应用程序内的按钮将应用程序最小化到后台?

Is there a way to minimize the app to the background with a button inside the app?

有没有办法通过应用内的按钮将应用最小化到背景?

有些应用会在您按下退出选项时执行此操作。他们不关闭而是将应用程序置于后台...

我想用我的 Ionic 应用程序或 cordova 方式来实现。

您可以使用 intent logic. Here is the android code you can find there

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

剩下的让你翻译成cordova/ionic(不知道那个框架)

我刚刚为 cordova 创建了一个名为“AppMinimize”的插件(仅适用于 Android 设备),它可以执行您的操作想。希望对你有帮助。


安装:

cordova plugin add https://github.com/tomloprod/cordova-plugin-appminimize.git

用法:

window.plugins.appMinimize.minimize();

Ionic 示例:按返回按钮最小化应用程序:

$ionicPlatform.registerBackButtonAction(function (event) {
    event.preventDefault();
    window.plugins.appMinimize.minimize();
}, 100);

Github:

https://github.com/tomloprod/cordova-plugin-appminimize

如果您使用的是 ionic-3,docs 的解决方案就像 charm

  1. 安装 Cordova 和 Ionic Native 插件:

    $ ionic cordova plugin add cordova-plugin-appminimize 
    
    $ npm install --save @ionic-native/app-minimize
    
  2. 将此插件添加到您应用的模块中

  3. 用法

    import { Platfrom } from 'ionic-angular';
    import { AppMinimize } from '@ionic-native/app-minimize';    
    
    constructor(private platform: Platform, private appMinimize: AppMinimize) { }
    
    ...
    
    this.platform.registerBackButtonAction(() => {
    this.appMinimize.minimize();
    });