Home > Java > Open application from foreground service when application is closed

Open application from foreground service when application is closed

WBOY
Release: 2024-02-09 17:10:08
forward
1081 people have browsed it

php editor Apple here introduces a very practical application operation method, that is, when the application is closed, the application can be reopened through the foreground service. This method allows the application to keep running in the background so that users can use it at any time. With simple steps, you can easily implement this function. Let’s take a look at the specific operation method!

Question content

So I use this code to open another app using my code (android studio, java):

Intent i = getFeatureManager().getMainMenu().getMainActivity().getPackageManager().
                getLaunchIntentForPackage(getSettingByName("Launch Package").getSValue());

        if (i == null) {
            return;
        }
        getFeatureManager().getMainMenu().getMainActivity().startActivity(i);
Copy after login

and i have foreground service, when my app is running in background and my app is closed, nothing happens, even if my app is closed, how can i make it work

The only thing I've found related to this is that it's not possible when I know it's coming from another app, I have an app that opens on its own and the app is always running in the foreground

Solution

To achieve this, we need to add the system_alert_window permission to androidmanifest.xml

As shown below:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
Copy after login

and accept popups above other apps in android app settings

The above is the detailed content of Open application from foreground service when application is closed. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template