起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5390|回复: 6

[结贴] APP后台运行在状态栏出现Doing heavy tasks怎么去掉?

[复制链接]

2

主题

6

帖子

38

积分

新手上路

Rank: 1

积分
38
QQ
发表于 2017-8-2 16:58:43 | 显示全部楼层 |阅读模式
本帖最后由 dsong_wu 于 2017-8-2 17:01 编辑

使用了cordova.plugin.background-mode插件,想让app在后台运行的时候可以收到消息。但是app一旦在后台运行,状态栏就出现了提醒:App is running in background Doing heavy tasks。下面是用模拟器运行的截图
QQ图片20170802164819.png

我想把这个状态栏提醒禁止,怎么处理呢? 求助,谢谢!
使用的插件代码如下:
  1. if(this.wx){
  2.         justep.Util.hint("本应用暂时只支持android和ios平台");
  3. }
  4. var timer;

  5. document.addEventListener('deviceready', function() {
  6.         cordova.plugins.backgroundMode.onactivate = function() {
  7.            
  8.                 var counter = 0;

  9.       var loginuser = localStorage.getItem("userinfo");
  10.      if(loginuser)
  11.     {
  12.        var user = JSON.parse(loginuser);
  13.        var user_id = user.user_id;
  14.                    timer = setInterval(function() {
  15.                          //获取消息(省略后台请求)
  16.                           counter=2;
  17.                    if(counter>0)
  18.                    {
  19.                                   if (device.platform != 'Android') {
  20.                                          cordova.plugins.notification.badge.set(counter);
  21.                                   }
  22.                                   else{
  23.                                          cordova.plugins.backgroundMode.configure({
  24.                                                  text : '有' + counter + '条新消息'
  25.                                          });
  26.                                   }
  27.                            }
  28.                    }, 10000);
  29.                 }
  30.         };
  31. cordova.plugins.backgroundMode.ondeactivate = function() {

  32. var loginuser = localStorage.getItem("userinfo");
  33. if(loginuser)
  34.     {
  35.                   clearInterval(timer);
  36.                   cordova.plugins.notification.badge.clear();
  37. }        
  38.                
  39.         };
  40. }, false);

  41. cordova.plugins.backgroundMode.enable();
复制代码

发表于 2017-8-2 17:47:58 | 显示全部楼层
这个是因为 cordova.plugin.background-mode  插件自动弹出来的吗??

可以修改下插件的源码
/Native/plugins/de.appplant.cordova.plugin.background-mode/www/background-mode.js

搜下字符串
App is running in background
改一下,代码
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

2

主题

6

帖子

38

积分

新手上路

Rank: 1

积分
38
QQ
 楼主| 发表于 2017-8-3 11:12:28 | 显示全部楼层
liangyongfei 发表于 2017-8-2 17:47
这个是因为 cordova.plugin.background-mode  插件自动弹出来的吗??

可以修改下插件的源码

找到该插件的代码,发现默认的通知Doing heavy tasks。怎么禁用呢?代码如下:
  1. /*
  2.     Copyright 2013-2014 appPlant UG

  3.     Licensed to the Apache Software Foundation (ASF) under one
  4.     or more contributor license agreements.  See the NOTICE file
  5.     distributed with this work for additional information
  6.     regarding copyright ownership.  The ASF licenses this file
  7.     to you under the Apache License, Version 2.0 (the
  8.     "License"); you may not use this file except in compliance
  9.     with the License.  You may obtain a copy of the License at

  10.      http://www.apache.org/licenses/LICENSE-2.0

  11.     Unless required by applicable law or agreed to in writing,
  12.     software distributed under the License is distributed on an
  13.     "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14.     KIND, either express or implied.  See the License for the
  15.     specific language governing permissions and limitations
  16.     under the License.
  17. */

  18. var exec    = require('cordova/exec'),
  19.     channel = require('cordova/channel');


  20. // Override back button action to prevent being killed
  21. document.addEventListener('backbutton', function () {}, false);

  22. // Called before 'deviceready' listener will be called
  23. channel.onCordovaReady.subscribe(function () {
  24.     // Device plugin is ready now
  25.     channel.onCordovaInfoReady.subscribe(function () {
  26.         // Set the defaults
  27.         exports.setDefaults({});
  28.     });

  29.     // Only enable WP8 by default
  30.     if (['WinCE', 'Win32NT'].indexOf(device.platform) > -1) {
  31.         exports.enable();
  32.     }
  33. });


  34. /**
  35. * @private
  36. *
  37. * Flag indicated if the mode is enabled.
  38. */
  39. exports._isEnabled = false;

  40. /**
  41. * @private
  42. *
  43. * Flag indicated if the mode is active.
  44. */
  45. exports._isActive = false;

  46. /**
  47. * @private
  48. *
  49. * Default values of all available options.
  50. */
  51. exports._defaults = {
  52.     title:  'App is running in background',
  53.     text:   'Doing heavy tasks.',
  54.     ticker: 'App is running in background',
  55.     resume: true,
  56.     silent: false
  57. };


  58. /**
  59. * Activates the background mode. When activated the application
  60. * will be prevented from going to sleep while in background
  61. * for the next time.
  62. */
  63. exports.enable = function () {
  64.     this._isEnabled = true;
  65.     cordova.exec(null, null, 'BackgroundMode', 'enable', []);
  66. };

  67. /**
  68. * Deactivates the background mode. When deactivated the application
  69. * will not stay awake while in background.
  70. */
  71. exports.disable = function () {
  72.     this._isEnabled = false;
  73.     cordova.exec(null, null, 'BackgroundMode', 'disable', []);
  74. };

  75. /**
  76. * List of all available options with their default value.
  77. *
  78. * @return {Object}
  79. */
  80. exports.getDefaults = function () {
  81.     return this._defaults;
  82. };

  83. /**
  84. * Overwrite default settings
  85. *
  86. * @param {Object} overrides
  87. *      Dict of options which shall be overridden
  88. */
  89. exports.setDefaults = function (overrides) {
  90.     var defaults = this.getDefaults();

  91.     for (var key in defaults) {
  92.         if (overrides.hasOwnProperty(key)) {
  93.             defaults[key] = overrides[key];
  94.         }
  95.     }

  96.     if (device.platform == 'Android') {
  97.         cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);
  98.     }
  99. };

  100. /**
  101. * Configures the notification settings for Android.
  102. * Will be merged with the defaults.
  103. *
  104. * @param {Object} options
  105. *      Dict with key/value pairs
  106. */
  107. exports.configure = function (options) {
  108.     var settings = this.mergeWithDefaults(options);

  109.     if (device.platform == 'Android') {
  110.         cordova.exec(null, null, 'BackgroundMode', 'configure', [settings, true]);
  111.     }
  112. };

  113. /**
  114. * If the mode is enabled or disabled.
  115. *
  116. * @return {Boolean}
  117. */
  118. exports.isEnabled = function () {
  119.     return this._isEnabled;
  120. };

  121. /**
  122. * If the mode is active.
  123. *
  124. * @return {Boolean}
  125. */
  126. exports.isActive = function () {
  127.     return this._isActive;
  128. };

  129. /**
  130. * Called when the background mode has been activated.
  131. */
  132. exports.onactivate = function () {};

  133. /**
  134. * Called when the background mode has been deaktivated.
  135. */
  136. exports.ondeactivate = function () {};

  137. /**
  138. * Called when the background mode could not been activated.
  139. *
  140. * @param {Integer} errorCode
  141. *      Error code which describes the error
  142. */
  143. exports.onfailure = function () {};

  144. /**
  145. * @private
  146. *
  147. * Merge settings with default values.
  148. *
  149. * @param {Object} options
  150. *      The custom options
  151. *
  152. * @return {Object}
  153. *      Default values merged
  154. *      with custom values
  155. */
  156. exports.mergeWithDefaults = function (options) {
  157.     var defaults = this.getDefaults();

  158.     for (var key in defaults) {
  159.         if (!options.hasOwnProperty(key)) {
  160.             options[key] = defaults[key];
  161.             continue;
  162.         }
  163.     }

  164.     return options;
  165. };
复制代码
回复 支持 反对

使用道具 举报

发表于 2017-8-3 14:35:14 | 显示全部楼层
dsong_wu 发表于 2017-8-3 11:12
找到该插件的代码,发现默认的通知Doing heavy tasks。怎么禁用呢?代码如下:
...

自己跟下代码!找下可疑的代码是什么!注释掉代码就行了!
我觉得应该是
cordova.exec(null, null, 'BackgroundMode', 'configure', [defaults, false]);

你试试吧!
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

17

主题

130

帖子

274

积分

中级会员

Rank: 3Rank: 3

积分
274
QQ
发表于 2017-8-29 17:23:08 | 显示全部楼层
好了吗
回复

使用道具 举报

2

主题

6

帖子

38

积分

新手上路

Rank: 1

积分
38
QQ
 楼主| 发表于 2017-9-3 18:59:43 | 显示全部楼层

可以了,把 exports._defaults中的silent改为true就可以了
回复 支持 反对

使用道具 举报

12

主题

22

帖子

67

积分

初级会员

Rank: 2

积分
67
QQ
发表于 2018-3-24 18:40:00 | 显示全部楼层
解决了我的问题
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-9-28 05:28 , Processed in 0.068078 second(s), 26 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表