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

Unlock and wakeup methods are not working #492

Open
Taxi4you opened this issue Jan 7, 2020 · 5 comments
Open

Unlock and wakeup methods are not working #492

Taxi4you opened this issue Jan 7, 2020 · 5 comments

Comments

@Taxi4you
Copy link

Taxi4you commented Jan 7, 2020

That's what I am trying to do:

cordova.plugins.backgroundMode.wakeUp()
cordova.plugins.backgroundMode.unlock()

But the app only popped up when the screen is on and in the homescreen.
When screen is off, the screen just getting ignited and the unlock with code is still required.
When trying to ignite it when other apps are on the foreground, nothing happens.
Even when I made WhatsApp on the foreground and minized it to be on the background, the method actually launched WhatsApp instead of my app..

BTW, is this suppose to support iOS?

@arvindder
Copy link

I am facing a similar issue where calling the method unlock it brings forward the app that's in the top of the foreground or app drawer stack on android.

@orhan-swe
Copy link

orhan-swe commented Jan 29, 2020

@Taxi4you @arvindder
Hi, did you maybe manage to resolve this issue?

Having the same issue, my sample code is below, running on android, I am using local notification plugin to trigger a callback after 10 seconds. That calls background-mode code when phone in sleep to unlock. Everything works fine, callback fires but unlock() does nothing..

onDeviceReady: function() {
        console.log("Device ready..");
        cordova.plugins.backgroundMode.enable();
        cordova.plugins.notification.local.schedule({
            trigger: { in: 10, unit: 'second' },
            silent: true
        });
        cordova.plugins.notification.local.on("trigger", () => {
            cordova.plugins.backgroundMode.unlock();
        });
    },

@arvindder
Copy link

arvindder commented Feb 2, 2020

@Taxi4you @arvindder
Hi, did you maybe manage to resolve this issue?

Having the same issue, my sample code is below, running on android, I am using local notification plugin to trigger a callback after 10 seconds. That calls background-mode code when phone in sleep to unlock. Everything works fine, callback fires but unlock() does nothing..

onDeviceReady: function() {
        console.log("Device ready..");
        cordova.plugins.backgroundMode.enable();
        cordova.plugins.notification.local.schedule({
            trigger: { in: 10, unit: 'second' },
            silent: true
        });
        cordova.plugins.notification.local.on("trigger", () => {
            cordova.plugins.backgroundMode.unlock();
        });
    },

I stopped using this plugin and moved to push notifications and service workers for my app's use case.

@Taxi4you
Copy link
Author

Whats service workers are?

@orhan-swe
Copy link

@arvindder
Thanks for your answer!

The reason this did not work for me was that I was using local notification plugin to trigger a wakeup, there seems to be a problem when that plugin is triggering background mode wakeUp.
We have a trigger from a bluetooth scan and when using that trigger this is working on android just fine.

This is the function that is called (as callback) when we get a signal from bluetooth while phone is in sleep (I am not sure we need all five function calls below but this is what works for us, and as doc says this is only supported on android):

  androidWakeUp() {

       cordova.plugins.backgroundMode.overrideBackButton();
       cordova.plugins.backgroundMode.wakeUp();
       cordova.plugins.backgroundMode.moveToForeground();

       // must be here for it to work..
       cordova.plugins.backgroundMode.unlock();
       cordova.plugins.backgroundMode.disable();
   },

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