Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android 10 start activity from background not working, foreground() and unlock() not working #499

Open
lucianfcorodeanu opened this issue Feb 7, 2020 · 5 comments

Comments

@lucianfcorodeanu
Copy link

Android 10 start activity from background not working, foreground() and unlock() not working.

@lucianfcorodeanu
Copy link
Author

Yes, i confirm ANDROID 10 is restrictive on starting activity from background, not allowed on API 29 / ANDROID 10, you must go to SETTINGS → Apps → Your App → Advanced → “Show app on top”, and NOW will work.
Just test it on CORDOVA and emulate with an ANDROID 10 version. Send it to background and then after a few seconds try to bring it back with unlock() or foreground();

Thanks.

@lucianfcorodeanu
Copy link
Author

lucianfcorodeanu commented Feb 8, 2020

I worked out a temporary fix, is working perfect.

Change files:

→ BackgroundModeExt.java

    //look for execute function that starts with `public boolean execute(etc, etc)`
    //right under in switch(action){ etc }, add this:
        case "permissionontop":
            RequestPermission();
        break;


    //send user to settings panel where he must allow "app on top" option
    //it makes sure only for ANDROID 10+ versions
    private void RequestPermission() {

        if (SDK_INT < 29) {
            return;
        }

        Activity activity = cordova.getActivity();
        Intent intent = new Intent(ACTION_MANAGE_OVERLAY_PERMISSION);

        cordova.getActivity().startActivity(intent);
    }

→ background-mode.js
Add this function

/**
 * Set permission to run on top > API 29.
 *
 * @return [ Void ]
 */
exports.permissionOnTop = function()
{
    if (this._isAndroid)
    {
        cordova.exec(null, null, 'BackgroundModeExt', 'permissionontop', []);
    }
};

→ In your cordova project

//it will send the user to app settings to allow app on top
cordova.plugins.backgroundMode.permissionOnTop();

rammie added a commit to rammie/cordova-plugin-background-mode that referenced this issue Mar 16, 2020
rammie added a commit to rammie/cordova-plugin-background-mode that referenced this issue Mar 16, 2020
ugenit pushed a commit to ugenit/cordova-plugin-background-mode that referenced this issue Aug 7, 2020
ugenit pushed a commit to ugenit/cordova-plugin-background-mode that referenced this issue Aug 7, 2020
@b1tw0rker
Copy link

Hi
I get these error:

D/SystemWebChromeClient: file:///android_asset/www/index.html: Line 125 : Uncaught TypeError: cordova.plugins.backgroundMode.permissionOnTop is not a function

What do i make wrong ?

@b1tw0rker
Copy link

Got to make ich working.
But at least, in Android 10 the App: ACTION_MANAGE_OVERLAY_PERMISSION can not add new apps :-(
What is todo, that my app ist listed there also?

@busslina
Copy link

I can confirm that enabling "Show on top" permission on Android 10 makes it working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants