Phonegap - transition from background to foreground
I am developing my team along with an application that needs to run in the background when an event triggered by sockets needs to bring the application to the fore.
The application should appear in the foreground similar to the call to viber or whatsapp. I stopped there. My app can now make sound and vibrate, but I need to draw the screen in the foreground.
I am using phone difference 5.1.1.
I have this plugin: https://github.com/katzer/cordova-plugin-background-mode
Can anyone give me a hand? I am very grateful for that.
source to share
I found a way! Using the plugin "toForeground". https://github.com/caioladislau/cordova-toforeground
cordova.plugins.backgroundMode.enable();
cordova.plugins.backgroundMode.onactivate = function() {
setTimeout(function(){
toForeground("MainActivity", "com.me.myapp", function() {
navigator.notification.vibrate(1000);
}, function(){
navigator.notification.vibrate(5000);
});
}, 4000);
};
Note where it is called:
toForeground(mainClassName, packageName, successFunction, errorFunction);
To find "mainClassName" and "packageName" I searched: platform / android / src / com / me / myapp / MainActivity.java and I found:
package com.me.myapp;
import android.os.Bundle;
import org.apache.cordova.*;
public class MainActivity extends CordovaActivity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
// Set by <content src="index.html" /> in config.xml
loadUrl(launchUrl);
}
}
source to share