如何检查移动网络浏览器是在移动设备的前台运行还是在后台运行 [英] how to check mobile web browser is running in foreground or background on mobile device
问题描述
我正在创建angularjs html5应用程序.
I am creating angularjs html5 application.
一个小的查询,我们可以在移动Web应用程序中使用pause \ resume事件吗?或回答我的查询如何检查浏览器窗口将重点放在移动网络浏览器"上
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 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.
推荐答案
添加cordova后台模式插件
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
有关更多信息,请检查此链接: https://github.com/katzer/cordova-plugin-background-mode
For more information check this link : https://github.com/katzer/cordova-plugin-background-mode
步骤如下:
-
首先安装cordova-plugin-device,因为cordova-plugin-background-mode依赖于它.在此之后,安装了科尔多瓦插件背景模式
First you install cordova-plugin-device, as cordova-plugin-background-mode is dependent on it. After this install cordoba-plugin-background mode
cordova插件添加 https://github.com/katzer/cordova-plugin-background-mode.git
cordova plugin add https://github.com/katzer/cordova-plugin-background-mode.git
现在您已经安装了它们两者,在控制器内部添加此代码
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');
}
});
步骤2是您调试插件是否工作的方法.在"if"块中,执行您要在后台模式下执行的操作.
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.
将此控制器添加到每次都被调用的HTML页面中.就像我在Home.html上添加了此控制器一样.
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.
这篇关于如何检查移动网络浏览器是在移动设备的前台运行还是在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!