简体   繁体   English

当 React Native Android 应用程序在后台或已被杀死时,如何将其带到前台?

[英]How to bring a React Native Android app to the foreground when it is in the background or has been killed?

Is there any way to bring a React Native app to the foreground when it is in the background or has been killed?当 React Native 应用程序在后台或被杀死时,有什么方法可以将它带到前台?

I have tried using react-native-invoke-app but it is no longer being maintained and only supports Android versions < 9.我曾尝试使用react-native-invoke-app但它不再被维护并且仅支持 Android 版本 < 9。

I think the best way to do this can be setting a URL scheme and opening the url connected to the app.我认为最好的方法是设置 URL 方案并打开连接到应用程序的 url。

1- add this line of code 1-添加这行代码

<data android:scheme=“my-awesome-app” /> in ./android/app/src/main/AndroidManifest.xml under the <intent-filter> under <activity> tag. <data android:scheme=“my-awesome-app” /><activity>标签下的<intent-filter>下的./android/app/src/main/AndroidManifest.xml中。

This will give a scheme to your app which is useful in deepLinking and opening your app with a browser or while you're in other apps.这将为您的应用程序提供一个方案,该方案在使用浏览器或在其他应用程序中进行深度链接和打开您的应用程序时很有用。 Actually if you open the my-awesome-app:// url, you're app will be opened.实际上,如果您打开my-awesome-app:// url,您的应用程序将被打开。

2- write a headless task or an event listener to run the Linking.openURL(my-awesome-app://); 2-编写无头任务或事件侦听器来运行Linking.openURL(my-awesome-app://);

this is an example from react-native-firebase message listener.这是 react-native-firebase 消息监听器的一个例子。

import firebase from 'react-native-firebase';
import {Linking} from 'react-native';

firebase.messaging().onMessage((message) => {
    // Process your message as required
    Linking.openURL('my-awesome-app://')
  });
}

To set the url scheme setting on iOS, you must add it in URL types in info.plist file like the picture below.要在 iOS 上设置 url 方案设置,您必须将其添加到info.plist文件中的 URL 类型中,如下图所示。

iOS 设置 url 方案

暂无
暂无

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

相关问题 Android如何在用户杀死应用程序后继续运行后台服务? - Android How to keep Running the background service when app is killed by user? GPS位置更改时如何将Android应用程序带回前台 - How to bring back an Android application to foreground when GPS location is changed 应用程序被杀死时后台TimerTask被杀死 - Background TimerTask gets killed when app is killed 当应用程序被杀死时,WorkManager 是否应该已经在工作,或者它是否需要附加一个前台服务? - Android工作室 - Should WorkManager already be working when the app is killed, or does it need to have a foreground service attached? - Android Studio 当应用程序被杀死时,AlarmManager 在前台服务中不起作用 - AlarmManager does not work in foreground service, when app was killed 在Android设置应用程序图标时的应用程序图标上的徽章编号或在接收Facebook应用程序等通知时被杀死 - On Android setting badge number on app icon when app is in background or killed when receiving notification like facebook app 被杀死后,如何在我的Java应用程序中做一些事情? - How can I do some stuff in my java app, after it has been killed? “杀死”后在后台运行Android应用程序 - Running Android App in the Background after “killed” 当应用程序被杀死或不在后台时如何检测来电号码和去电号码 Android 8.0,9.0 - How to detect Incoming call number and Out going call number when app is killed OR not in background Android 8.0,9.0 以编程方式将 Android 应用程序从后台带回 - Bring Android app back from background programmatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM