How to show up a modal on phone when the user is not viewing the app?


#1

Hello
I am writing an small messaging app for my employees. This app works with Node.js server. Everything is ok, except this feature:

I want to turn the screen on and show up the message inside a modal when an employee receives it, even when he/she is not viewing the app, even when his/her phone is locked? Does Ionic Popup/Modal service do it for me? This feature I want to implement is like Android’s Messaging app or Viber.

I didn’t find anything over the net.

Any help is appreciated


How to keep application running when the screen is off
#2

Modal can be only displayed within app… what you might be looking for is a notification…
have a look at push notification and Google Cloud messagein

https://developer.android.com/google/gcm/index.html


#3

You can test my plugin (fork of https://github.com/Viras-/cordova-plugin-powermanagement) : https://github.com/jimibi/cordova-plugin-powermanagement.
It must solve a lot of your problems.


#4

@harshitgoel96 my app has push notifications, I want a box show up in the users’ screen, showing the preview of the message, a text box to reply and some buttons to close the box or view the message in app. I don’t know how to bring it up.


#5

Thanks, this plugin helps me to turn the screen on, but I didn’t find any way to show up the message box on the screen, yet.


#6

i just checked the plugin… if the alert box is shown without the app being active, then in the same place load a custom modal…

  sucAlert = function() {
        alert('Success');

//place model here
//$ionicModal.fromTemplate();
    };
    errAlert = function() {
        alert('Error');
    };
    powerManagement.acquire(sucAlert, errAlert); // awake the smartphone
    powerManagement.release(sucAlert, errAlert); // allowed to sleep again

#7

Uses callBack function, like this:

  sucFunction = function () {
          //Modal call
  },
  errAlert = function () {
         alert('Error');
  },
  sucAlert = function () {
         toForeground('StarterApp', 'com.ionicframework.starter', sucFunction, errAlert);
  };
  powerManagement.acquire(sucAlert, errAlert);
  powerManagement.release(sucFunction, errAlert);

#8

just a query… would your plugin be working when the app is closed ??

EDIT and what does toForeground does ??? where can i look for it ?


#9

No, the application must be in background or in foreground


#10

A plugin for codova, which will allow the app to bring itself, or other app activites, to the foreground.

Fork this plugin: https://github.com/jimibi/cordova-toforeground


#11

@jimibi tell me please if it is possible with your plugin on Android to keep an application (cordova/phonegap) in memory and active? I’ve noticed that even if I use wake lock (not from your plugin), my app is getting less and less active and finally it is stopped by the system. The app is supposed to do a task each minute. At the beginning it works correctly and then the period between calling the timer is getting longer and finally the app is stopped. If I connect external power source it works correctly, but on battery Android is lulling it and I cannot do anything to prevent this. Is anything (without external service) possible to achieve this functionality of keeping an app active and do some task each minute forever?


#13

No, for this use: https://github.com/katzer/cordova-plugin-background-mode