0

I am creating angularjs html5 application.

A small query, can we make use of pause\resume events in mobile web application? or answer my query how to check if browser window has focus in "mobile web browser"

I got reference how to check app running in foreground or background in ionic/cordova/phonegap

I am totally unaware if cordova\ng-cordova can be used in mobile web browser, if someone can guide me that will be great help. I want to basically track any event when application is active such as - phone call is received
- home press button.

All these events I want to track in mobile web browser.

Community
  • 1
  • 1
PavanT
  • 81
  • 8
  • I know that jQuery has pagehide and pageshow events which fired when you leave and enter from/to page. I never used them, but you can try :) – NechiK Feb 28 '17 at 20:25
  • I have tried events like pagehide, onblur, visibilitychange, but none of them helped. I would like to know if cordova can be used in mobile web browser version. Since I understand cordova has onPause event, but this event is initalized in mobile web browser. – PavanT Mar 01 '17 at 04:25

1 Answers1

0

Add cordova background mode plugin

cordova plugin add cordova-plugin-background-mode 

Once the plugin has been enabled and the app has entered the background, the background mode becomes active.

cordova.plugins.backgroundMode.isActive(); // => boolean

For more information check this link : https://github.com/katzer/cordova-plugin-background-mode

Steps are as follows:

  1. First you install cordova-plugin-device, as cordova-plugin-background-mode is dependent on it. After this install cordoba-plugin-background mode

    cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git

  2. Now that you've installed both of them, inside your controller add this code

     .controller('HomeCtrl', function($scope){
    
            if(cordova.plugins.backgroundMode.isActive()){
               console.log("Background state");
            }else{
               alert('HELLO');
            }
     });
    
  3. Step 2 is the way you can debug if your plugin is working or not. In the 'if' block do what you want to do in background mode.

  4. Add this controller to an HTML page which is called every time. Like I have added this controller on Home.html.

Tell me if you got any problem.

Akash KR
  • 778
  • 3
  • 11
  • Hello Akash, thanks for headsup. I am using visualstudio and web development in mvc. I have included cordova.js and background-mode.js. Inlayout I have used cordova.plugins.backgroundMode.isActive();, but its not working. What steps I need to follow, - How to setup cordova only related to above library? - what are steps – PavanT Mar 01 '17 at 11:23
  • I would like to know if the cordova webview, will need to be separately programmed for each platform like IOS and android? I am unable to setup cordova in my visual studio project. I referred below link, https://cordova.apache.org/docs/en/latest/guide/hybrid/webviews/ What I would like to know for setting up cordova, are there several steps like include cordova.js, include config.xml (if yes how shall I configure this xml?) – PavanT Mar 03 '17 at 11:06