简体   繁体   English

如何在颤动中将应用程序从后台带到前台

[英]How to bring an app from background to foreground in flutter

I have an app that is managing audio calls.我有一个管理音频呼叫的应用程序。 When a call is made to the add and the app is running in the background I need to bring the app in the foreground state.当调用 add 并且应用程序在后台运行时,我需要将应用程序置于前台状态。 I tried to use Navigator.我尝试使用导航器。 push but without any result.推但没有任何结果。

You can use the package bringtoforeground .您可以使用包bringtoforeground It's fairly in the early stages with respect to its version but it works.就其版本而言,它还处于早期阶段,但它确实有效。

iOS iOS

But this only works on android, you have to keep in mind that iOS apps that are on the background are destroyed.但这仅适用于 android,您必须记住,后台的 iOS 应用程序已被破坏。 you can read this do see details here您可以阅读此内容,请在此处查看详细信息

Android安卓

So this implementation will only work on Android.所以这个实现只适用于Android。

The best thing with this package is that you can use it with Firebase Cloud Messaging (FCM) or any other for that matter.这个包最好的地方是你可以将它与 Firebase Cloud Messaging (FCM) 或其他任何东西一起使用。

This is their example, Bringtoforeground.bringAppToForeground();这是他们的例子, Bringtoforeground.bringAppToForeground(); this is the piece of code you use to bring your app to the foreground.这是您用来将应用程序置于前台的代码。

import 'dart:async';

import 'package:bringtoforeground/bringtoforeground.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      Timer.periodic(Duration(seconds: 10), (t) {
        Bringtoforeground.bringAppToForeground(); //This is the only thing that matters
      });
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Text('Running on: $_platformVersion\n'),
        ),
      ),
    );
  }
}

Install flutter_foreground_task package here is在这里安装flutter_foreground_task

and use FlutterForegroundTask.minimizeApp() for app to background并将FlutterForegroundTask.minimizeApp()用于应用程序到后台
and use FlutterForegroundTask.launchApp() for app to foreground that's all.并使用FlutterForegroundTask.launchApp()将应用程序置于前台即可。 I think it helps.我认为它有帮助。

You can try app_to_foreground plugin.你可以试试app_to_foreground插件。

It works only for android它仅适用于安卓

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将应用程序从后台带到前台 - How to bring an app from background to foreground 如何在颤振集成测试中将应用程序带到前台 - How to bring app to foreground in flutter integration test 如何在不将应用程序置于前台的情况下关闭 flutter 中的本地通知 - How to dismiss local notification in flutter without bring app in foreground Flutter-Android如何在应用程序处于前台/后台时使用相机 - Flutter-Android how to use the camera while the app is in foreground/background 如何在 flutter 中后台或前台运行计时器甚至应用程序? - How to run timer even app in background or foreground in flutter? Flutter - 如何在后台运行我们的应用程序而另一个应用程序占据前台? - Flutter - How to run our app in the background while another app takes the foreground? 在 flutter 中创建在后台和前台运行的应用程序的简单方法是什么? - what is a simple way to create an app that runs in both background and foreground in flutter? flutter如何检测应用是否来自后台? - how to detect if the app is coming from the background in flutter? 不在前台的Flutter Focus应用 - Flutter Focus App That Is Not In Foreground 当我从后台 flutter 进入前台时,showDialog 不可见 - showDialog not visible when I come into the foreground from the background flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM