chenyidong месяцев назад: 4
Родитель
Сommit
d7b030fbc7
24 измененных файлов с 1039 добавлено и 2 удалено
  1. 34 0
      App.vue
  2. 2 2
      manifest.json
  3. 143 0
      uni_modules/android-keeplive/changelog.md
  4. 2 0
      uni_modules/android-keeplive/encrypt
  5. 109 0
      uni_modules/android-keeplive/package.json
  6. 490 0
      uni_modules/android-keeplive/readme.md
  7. 6 0
      uni_modules/android-keeplive/utssdk/app-android/config.json
  8. BIN
      uni_modules/android-keeplive/utssdk/app-android/index.uts
  9. BIN
      uni_modules/android-keeplive/utssdk/app-android/libs/cactus-release.aar
  10. BIN
      uni_modules/android-keeplive/utssdk/app-android/res/drawable/icon.png
  11. 91 0
      uni_modules/android-keeplive/utssdk/app-harmony/ForegroundService.ets
  12. 100 0
      uni_modules/android-keeplive/utssdk/app-harmony/ServiceManager.ets
  13. BIN
      uni_modules/android-keeplive/utssdk/app-harmony/index.uts
  14. 20 0
      uni_modules/android-keeplive/utssdk/app-harmony/module.json5
  15. 20 0
      uni_modules/android-keeplive/utssdk/app-harmony/resources/base/element/string.json
  16. BIN
      uni_modules/android-keeplive/utssdk/app-ios/KeepLive.swift
  17. BIN
      uni_modules/android-keeplive/utssdk/app-ios/Resources/main.mp3
  18. 3 0
      uni_modules/android-keeplive/utssdk/app-ios/config.json
  19. BIN
      uni_modules/android-keeplive/utssdk/app-ios/index.uts
  20. 18 0
      uni_modules/android-keeplive/utssdk/app-ios/info.plist
  21. BIN
      uni_modules/android-keeplive/utssdk/app-ios/info.zip
  22. 0 0
      uni_modules/android-keeplive/utssdk/interface.uts
  23. 1 0
      uni_modules/android-keeplive/utssdk/unierror.uts
  24. BIN
      uni_modules/android-keeplive/utssdk/utssdk.zip

+ 34 - 0
App.vue

@@ -6,6 +6,7 @@
6
 	import {
6
 	import {
7
 		callErrorCode
7
 		callErrorCode
8
 	} from "@/utils/commonDicts.js";
8
 	} from "@/utils/commonDicts.js";
9
+	import { KeepLive } from '@/uni_modules/android-keeplive'
9
 	// #endif
10
 	// #endif
10
 	import {
11
 	import {
11
 		simpleDebounce
12
 		simpleDebounce
@@ -61,6 +62,8 @@
61
 			// this.addFlags();
62
 			// this.addFlags();
62
 			
63
 			
63
 			this.$store.dispatch("call/startPhoneListener");
64
 			this.$store.dispatch("call/startPhoneListener");
65
+			
66
+			this.startKeepLive();
64
 
67
 
65
 
68
 
66
 			// #endif
69
 			// #endif
@@ -69,6 +72,37 @@
69
 			this.$store.dispatch("app/register");
72
 			this.$store.dispatch("app/register");
70
 		},
73
 		},
71
 		methods: {
74
 		methods: {
75
+			startKeepLive(){
76
+				const keep =new KeepLive();
77
+				keep.setTitle("时与APP");
78
+				keep.setContent("后台运行中");
79
+				// keep.setLargeIcon("icon");
80
+				keep.setSmallIcon("icon"); //图标名字  图标放在 插件下面的 res/drawable 文件夹下
81
+				keep.onAddBackgroundCallback(function(res){
82
+				    // console.log("后台运行 "+res)
83
+				})
84
+				keep.onAddScrrenListenerCallback(function(res){
85
+				    // console.log("屏幕开启状态 "+res)
86
+				})  
87
+				keep.setWakeLock(1,"keeptag");// 设置唤醒类型
88
+				
89
+				keep.setAutoStartEnable(true)
90
+				if(!keep.checkAppNotification()){
91
+				    keep.onOpenNotificationSetting(function(res){
92
+				        keep.register();
93
+				        var ignoring=  keep.isIgnoringBatteryOptimizations();
94
+				        if(!ignoring){
95
+				            keep.requestIgnoreBatteryOptimizations();
96
+				        }
97
+				    })
98
+				}else{
99
+				    keep.register();
100
+				    var ignoring=  keep.isIgnoringBatteryOptimizations();
101
+				    if(!ignoring){
102
+				        keep.requestIgnoreBatteryOptimizations();
103
+				    }
104
+				}
105
+			},
72
 			wakeLock() {
106
 			wakeLock() {
73
 				//Android  
107
 				//Android  
74
 				var main = plus.android.runtimeMainActivity();
108
 				var main = plus.android.runtimeMainActivity();

+ 2 - 2
manifest.json

@@ -2,8 +2,8 @@
2
     "name" : "时与",
2
     "name" : "时与",
3
     "appid" : "__UNI__0C0EF72",
3
     "appid" : "__UNI__0C0EF72",
4
     "description" : "",
4
     "description" : "",
5
-    "versionName" : "1.1.9",
6
-    "versionCode" : 119,
5
+    "versionName" : "1.2.0",
6
+    "versionCode" : 120,
7
     "transformPx" : false,
7
     "transformPx" : false,
8
     /* 5+App特有相关 */
8
     /* 5+App特有相关 */
9
     "app-plus" : {
9
     "app-plus" : {

+ 143 - 0
uni_modules/android-keeplive/changelog.md

@@ -0,0 +1,143 @@
1
+## 1.1.70(2025-10-31)
2
+优化鸿蒙保活
3
+## 1.1.69(2025-10-27)
4
+优化已知问题
5
+## 1.1.68(2025-10-09)
6
+优化
7
+## 1.1.67(2025-09-28)
8
+修复so 16k 问题
9
+## 1.1.66(2025-09-11)
10
+优化已知问题
11
+## 1.1.65(2025-08-11)
12
+优化
13
+## 1.1.64(2025-07-28)
14
+优化
15
+## 1.1.63(2025-07-28)
16
+增加鸿蒙端
17
+## 1.1.62(2025-07-08)
18
+优化
19
+## 1.1.61(2025-07-08)
20
+优化
21
+## 1.1.60(2025-07-08)
22
+优化保活逻辑,修复已知问题
23
+## 1.1.59(2025-07-08)
24
+优化保活逻辑,修复已知问题
25
+## 1.1.58(2025-06-04)
26
+优化
27
+## 1.1.57(2025-05-20)
28
+优化
29
+## 1.1.56(2025-05-20)
30
+优化Android 
31
+## 1.1.55(2025-05-13)
32
+优化ios
33
+## 1.1.54(2025-05-13)
34
+优化iOS端
35
+## 1.1.53(2025-04-30)
36
+优化通知栏,其它优化
37
+## 1.1.52(2025-04-17)
38
+优化已知问题
39
+## 1.1.51(2025-04-15)
40
+优化
41
+## 1.1.50(2025-04-01)
42
+优化
43
+## 1.1.49(2025-03-14)
44
+优化
45
+## 1.1.48(2025-03-12)
46
+web 和微信小程序改uts 端优化
47
+## 1.1.47(2025-03-12)
48
+web 和微信小程序改uts 为js
49
+## 1.1.46(2025-03-11)
50
+优化
51
+## 1.1.45(2025-03-11)
52
+修复已知问题
53
+## 1.1.44(2025-03-07)
54
+新增通知栏角标设置 默认为关闭
55
+其它优化
56
+## 1.1.43(2025-03-04)
57
+修改插件名称
58
+## 1.1.38(2025-03-03)
59
+优化保活逻辑
60
+## 1.1.36(2025-02-26)
61
+优化iOS 端播放逻辑
62
+## 1.1.35(2025-02-24)
63
+优化
64
+## 1.1.34(2025-02-22)
65
+1.增加部分手机休眠的时候wifi 断开连接,使其保持连接
66
+2.ios端增加info。zip 需要的自行解压使用
67
+3.启动保活增加自动申请通知权限,无需再判断打开设置等
68
+## 1.1.32(2025-02-20)
69
+优化首次启动 部分手机卡顿问题
70
+## 1.1.31(2025-02-17)
71
+优化后台运行逻辑,增加程序后台活性
72
+## 1.1.30(2025-02-12)
73
+优化后台多进程保活
74
+## 1.1.29(2025-02-11)
75
+优化
76
+## 1.1.28(2025-02-11)
77
+优化
78
+## 1.1.27(2025-02-05)
79
+优化
80
+## 1.1.26(2025-02-03)
81
+优化
82
+## 1.1.25(2025-02-03)
83
+新增ios 端  
84
+## 1.1.23(2025-01-07)
85
+修复ios 端打包报错问题
86
+## 1.1.22(2025-01-06)
87
+修改已知问题
88
+## 1.1.21(2025-01-06)
89
+优化
90
+## 1.1.20(2025-01-02)
91
+修复取消全部定时器闪退问题
92
+## 1.1.19(2024-12-28)
93
+优化程序逻辑
94
+## 1.1.18(2024-12-22)
95
+优化
96
+## 1.1.17(2024-12-20)
97
+优化
98
+## 1.1.16(2024-12-19)
99
+去掉自启动权限
100
+## 1.1.15(2024-12-16)
101
+优化
102
+## 1.1.14(2024-12-13)
103
+防止后台录音时被释放
104
+## 1.1.13(2024-12-03)
105
+修复后台音乐bug
106
+## 1.1.12(2024-12-02)
107
+其它修改
108
+## 1.1.11(2024-11-30)
109
+修改出现编译错误问题
110
+## 1.1.10(2024-11-27)
111
+修复闪退
112
+## 1.1.9(2024-11-27)
113
+重复提交
114
+## 1.1.8(2024-11-27)
115
+新增唤醒cpu 功能
116
+## 1.1.7(2024-11-12)
117
+新增静默通知
118
+## 1.1.6(2024-11-04)
119
+增加web
120
+## 1.1.5(2024-11-02)
121
+修复已知问题
122
+## 1.1.4(2024-10-31)
123
+修改定时器小于60s 无法取消问题
124
+## 1.1.3(2024-10-31)
125
+增加全局保活
126
+## 1.1.2(2024-10-31)
127
+修复多个定时器错乱问题
128
+## 1.1.1(2024-10-30)
129
+修复已知问题
130
+## 1.0.6(2024-10-28)
131
+修复已知问题
132
+## 1.0.5(2024-10-28)
133
+修复编译出错问题
134
+## 1.0.4(2024-10-25)
135
+修改 回调函数已释放,不能再次执行问题
136
+## 1.0.3(2024-10-08)
137
+修复已知bug
138
+## 1.0.2(2024-09-26)
139
+修复已知bug
140
+## 1.0.1(2024-09-24)
141
+修复已知bug
142
+## 1.0.0(2024-09-19)
143
+初始化

+ 2 - 0
uni_modules/android-keeplive/encrypt

@@ -0,0 +1,2 @@
1
+Sץ©�FבSכ…›אe|�b₪�]ךQ³g‏T#‰9²ג#ִט�<¹—ֻ״I•–�;ׁ“7.—הד#©
םt¯«ר•סƒא�4†ל”^…›ײc8�'ֶ”?B–Fבr™§�יcNm! ׀ֽ
2
+Nf@µR�ֻJ”—w׳XUGִ�הׁתֵֽ6¾
9°™yַ

Разница между файлами не показана из-за своего большого размера
+ 109 - 0
uni_modules/android-keeplive/package.json


+ 490 - 0
uni_modules/android-keeplive/readme.md

@@ -0,0 +1,490 @@
1
+# android-keeplive
2
+### 本插件支持uniapp/uniappx 双端
3
+ 长期维护,有任何问题请在插件群联系作者
4
+### 功能介绍和注意事项
5
+
6
+### 源码版本安卓端不包含aar文件源码,其它端包含所有源码
7
+
8
+#### 本插件为后台无声音乐保活,为推送蓝牙后台传数据等保驾护,增加程序存活率,防止程序进入后台后或者系统休眠后程序停止执行的问题(用本插件定时器1和定时器2可保证任何状态下准确执行)无定位需求直接集成即可,若需要定位则合并集成作者定位插件
9
+
10
+1.android/iOS端需要自定义基座
11
+
12
+2.ios 端若觉得效果不佳,可以解压ios 插件目录下的uni_modules\android-keeplive\utssdk\app-ios\info.zip 将info.plist 文件和uts 文件在同一个级别 文件(上架可能会困难一点)
13
+ 
14
+3.推荐android端合井使用作者一像素保活效果更佳[链接](https://ext.dcloud.net.cn/plugin?id=20324)
15
+
16
+
17
+#### Android端 其它增加存活机会方法
18
+1.最近任务给程序加锁,2.在系统设置启动项开启应用程序后台运行
19
+
20
+
21
+#### 插件测试使用方法
22
+1. 选择试用,绑定要试用的项目appid,
23
+
24
+2. 选择后下载到对应的本地项目,
25
+
26
+3. 按照文档 -》把插件引入项目(即 import { KeepLive } from '@/uni_modules/android-keeplive' 需要先引入),
27
+
28
+4. 发布-》云打包-》选择制作基座-》打包等基座制作完成 
29
+
30
+5. 运行 -》 运行到手机或模拟器-》运行到Androidapp基座-》选择使用自定义基座运行-》选择手机-》运行
31
+
32
+6. 若之前手机安装过基座需要先卸载之前的基座
33
+
34
+### 安卓默认通知id为 6234542
35
+
36
+###  uniappx
37
+~~~
38
+// #ifdef APP
39
+import { KeepLive } from '@/uni_modules/android-keeplive' // 放在页面导入的地方
40
+// #endif
41
+
42
+
43
+//<!-- ------------------------------下方代码需要放进方法中-------------------------------------------------- -->	
44
+// #ifdef APP
45
+var keep=new KeepLive();
46
+keep.setTitle("app");
47
+keep.setContent("app is runing");
48
+// keep.setLargeIcon("icon");
49
+keep.setSmallIcon("icon"); //图标名字  图标放在 插件下面的 uni_modules\android-keeplive\utssdk\app-android\res 文件夹下
50
+keep.onAddBackgroundCallback(function(res:boolean){
51
+	console.log("后台运行 "+res)
52
+	
53
+})
54
+keep.onAddScrrenListenerCallback(function(res:boolean){
55
+	console.log("屏幕开启状态 "+res)
56
+	
57
+})	
58
+keep.setWakeLock(1,"keeptag");// 设置唤醒类型
59
+keep.setAutoStartEnable(true)
60
+
61
+if(!keep.checkAppNotification()){
62
+	keep.onOpenNotificationSetting(function(res:boolean){
63
+		keep.register();
64
+		var ignoring=  keep.isIgnoringBatteryOptimizations();
65
+		if(!ignoring){
66
+			keep.requestIgnoreBatteryOptimizations();
67
+		}
68
+	})
69
+}else{
70
+	keep.register();
71
+	var ignoring=  keep.isIgnoringBatteryOptimizations();
72
+	if(!ignoring){
73
+		keep.requestIgnoreBatteryOptimizations();
74
+	}
75
+}
76
+// 稳定定时器 需要的用户使用(默认定时器1 )
77
+keep.onStartCSystemTimer(60,function(){
78
+	console.log("onStartCSystemTimer ");
79
+	keep.acquire(1000);// 唤醒一秒钟
80
+});
81
+// 需要插件增加程序后台运行能力的可以加下面代码 想程序始终保持活性(即稳定推送 scocket等)(体验好) 还是建议用户打开系统设置 启动项 后台运行
82
+//keep.wifilock();//部分手机可能会断
83
+// 定时器时间改成10秒 去掉上方的
84
+//keep.onStartCSystemTimer(10,function(){
85
+//	console.log("onStartCSystemTimer ");
86
+//	keep.acquire(1000);// 唤醒一秒钟
87
+//});
88
+// #endif
89
+~~~
90
+
91
+
92
+###  uniapp
93
+~~~
94
+// #ifdef APP
95
+import { KeepLive } from '@/uni_modules/android-keeplive' // 放在页面导入的地方
96
+// #endif
97
+
98
+
99
+//<!-- ------------------------------下方代码需要放进方法中-------------------------------------------------- -->	
100
+// #ifdef APP	
101
+var keep=new KeepLive();
102
+keep.setTitle("app");
103
+keep.setContent("app is runing");
104
+// keep.setLargeIcon("icon");
105
+keep.setSmallIcon("icon"); //图标名字  图标放在 插件下面的 res/drawable 文件夹下
106
+keep.onAddBackgroundCallback(function(res){
107
+	console.log("后台运行 "+res)
108
+	
109
+})
110
+keep.onAddScrrenListenerCallback(function(res){
111
+	console.log("屏幕开启状态 "+res)
112
+	
113
+})	
114
+keep.setWakeLock(1,"keeptag");// 设置唤醒类型
115
+
116
+keep.setAutoStartEnable(true)
117
+if(!keep.checkAppNotification()){
118
+	keep.onOpenNotificationSetting(function(res){
119
+		keep.register();
120
+		var ignoring=  keep.isIgnoringBatteryOptimizations();
121
+		if(!ignoring){
122
+			keep.requestIgnoreBatteryOptimizations();
123
+		}
124
+	})
125
+}else{
126
+	keep.register();
127
+	var ignoring=  keep.isIgnoringBatteryOptimizations();
128
+	if(!ignoring){
129
+		keep.requestIgnoreBatteryOptimizations();
130
+	}
131
+}
132
+
133
+keep.onStartCSystemTimer(60,function(){
134
+	console.log("onStartCSystemTimer ");
135
+		keep.acquire(1000);// 唤醒一秒钟
136
+});
137
+// 需要插件增加程序后台运行能力的可以加下面代码 想程序始终保持活性(即稳定推送 scocket等)(体验好) 还是建议用户打开系统设置 启动项 后台运行
138
+//keep.wifilock();//部分手机可能会断
139
+// 定时器时间改成3秒 去掉上方的
140
+//keep.onStartCSystemTimer(3,function(){
141
+//	console.log("onStartCSystemTimer ");
142
+//	keep.acquire(1000);// 唤醒一秒钟
143
+//});
144
+// #endif
145
+~~~
146
+
147
+
148
+
149
+### 需要gps定位用户 可合并作者定位插件(推荐使用作者定时器1 ,系统休眠后可执行)
150
+#### 
151
+[安卓 ios 鸿蒙 原生gps定位](https://ext.dcloud.net.cn/plugin?id=21745)
152
+
153
+[安卓ios 高德定位](https://ext.dcloud.net.cn/plugin?id=20916)
154
+
155
+[安卓腾讯定位](https://ext.dcloud.net.cn/plugin?id=20875)(后续支持ios)
156
+
157
+[安卓ios 百度定位](https://ext.dcloud.net.cn/plugin?id=20562)
158
+
159
+#### uniappx
160
+
161
+~~~
162
+// #ifdef APP
163
+import { isProviderEnabled, openLocSetting,  onStartLocs,LocData,stop,LocationData} from "@/uni_modules/xtf-gpslocation"
164
+// #endif
165
+// #ifdef APP
166
+// 停用后台播放音乐
167
+keep.setBackgroundMusicEnabled(false);
168
+
169
+// 后台定位则需要使用插件的定时器 息屏也能执行,自定定时器易休眠停止执行
170
+// 先启动定位
171
+var on=isProviderEnabled();// 是否开启gps
172
+if(on){
173
+	keep.onStartCSystemTimer(60,function(){
174
+onStartLocs({
175
+    backgroud:true,
176
+} as LocData,function(data:LocationData){
177
+    console.log(data)
178
+})
179
+	
180
+	});	
181
+}
182
+// #endif
183
+
184
+
185
+~~~
186
+
187
+#### uniapp
188
+
189
+~~~
190
+import { isProviderEnabled, openLocSetting,  onStartLocs,LocData,stop} from "@/uni_modules/xtf-gpslocation"
191
+
192
+
193
+// 停用后台播放音乐
194
+keep.setBackgroundMusicEnabled(false);
195
+
196
+// 后台定位则需要使用插件的定时器 息屏也能执行,自定定时器易休眠停止执行
197
+// 先启动定位
198
+var on=isProviderEnabled();// 是否开启gps
199
+if(on){
200
+	keep.onStartCSystemTimer(60,function(){
201
+onStartLocs({
202
+    backgroud:true,
203
+} ,function(res){
204
+    console.log(res)
205
+})
206
+	
207
+	});	
208
+}
209
+
210
+
211
+
212
+~~~
213
+
214
+### 注册开启运行
215
+
216
+#### register
217
+~~~
218
+keep.register();
219
+~~~
220
+
221
+### 重启
222
+
223
+#### restart
224
+~~~
225
+keep.restart();
226
+~~~
227
+
228
+### 取消运行
229
+
230
+#### unregister
231
+~~~
232
+keep.unregister();
233
+~~~
234
+
235
+### 是否运行
236
+#### isRunning
237
+return  boolean
238
+~~~
239
+var run=keep.isRunning();
240
+~~~
241
+### 判断通知权限是否开启(安卓有效,ios 无功能)
242
+#### checkAppNotification
243
+~~~
244
+var on=keep.checkAppNotification();
245
+~~~
246
+
247
+#### 打开应用通知设置(安卓有效,ios 无功能)
248
+#### goNotificationSetting
249
+~~~
250
+keep.goNotificationSetting();
251
+~~~
252
+#### 打开应用通知设置并返回状态(安卓有效,ios 无功能)
253
+uniappx
254
+~~~
255
+	keep.onOpenNotificationSetting(function(on:boolean){
256
+	
257
+	})
258
+~~~
259
+uniapp
260
+~~~
261
+	keep.onOpenNotificationSetting(function(on){
262
+	})
263
+~~~
264
+
265
+### 通过包名打开应用程序(安卓有效,ios 无功能)
266
+#### doStartApplicationWithPackageName
267
+参数1 应用包名 string 
268
+~~~
269
+keep.doStartApplicationWithPackageName("com.test");
270
+~~~
271
+
272
+
273
+### 开启应用省电后台运行 (安卓有效,ios 无功能)
274
+#### requestIgnoreBatteryOptimizations
275
+~~~
276
+keep.requestIgnoreBatteryOptimizations();
277
+~~~
278
+
279
+### 判断应用是否开启省电后台运行 (安卓有效,ios 无功能)
280
+#### isIgnoringBatteryOptimizations
281
+return  boolean 
282
+~~~
283
+var ignoring=  keep.isIgnoringBatteryOptimizations();
284
+~~~
285
+
286
+### 设置后台无声音乐是否开启 (安卓有效,ios 无功能)
287
+#### setBackgroundMusicEnabled
288
+参数1 boolean
289
+~~~
290
+keep.setBackgroundMusicEnabled(true);
291
+~~~
292
+
293
+
294
+
295
+### 是否隐藏通知栏 (弃用,后续删除)
296
+#### hideNotification(安卓有效,ios 无功能)
297
+参数1 boolean
298
+~~~
299
+keep.hideNotification(false);
300
+~~~
301
+### 静音通知
302
+#### setNotifaicationSoundEnable
303
+ 参数1 boolean
304
+ ~~~
305
+ keep.setNotifaicationSoundEnable(true);
306
+ ~~~
307
+
308
+ 
309
+### 设置通知栏 ChannelId 默认keeplive(安卓有效,ios 无功能)
310
+#### setChannelId
311
+参数1 string 
312
+ ~~~
313
+ keep.setChannelId("keeplive");
314
+ ~~~
315
+ 
316
+### 更新通知栏
317
+#### updateNotification
318
+ ~~~
319
+keep.setTitle("Test");
320
+keep.setContent("test runing");
321
+keep.updateNotification();
322
+ ~~~
323
+
324
+### 设置通知栏标题
325
+#### setTitle
326
+参数1 string 
327
+ ~~~
328
+ keep.setTitle("title");
329
+ ~~~
330
+
331
+### 设置通知栏内容
332
+#### setContent
333
+参数1 string 
334
+ ~~~
335
+ keep.setContent("msg");
336
+ ~~~
337
+### 设置通知重要性(安卓有效,ios 无功能)
338
+#### setChannelImportance
339
+参数1 number  0-4 低到高 
340
+~~~
341
+keep.setChannelImportance(3);
342
+~~~
343
+
344
+
345
+### 设置通知栏小图标(安卓有效,ios 无功能)
346
+#### setSmallIcon
347
+参数1 string   插件的res  drawable 目录下 名称
348
+
349
+~~~
350
+ keep.setSmallIcon("icon");
351
+
352
+~~~
353
+
354
+### 设置通知栏大图标(安卓有效,ios 无功能)
355
+#### setLargeIcon
356
+参数1 string   插件的res  drawable 目录下 名称
357
+~~~
358
+ keep.setLargeIcon("icon");
359
+
360
+~~~
361
+
362
+### 设置唤醒cpu类型(安卓有效,ios 无功能)
363
+#### setWakeLock
364
+参数1 number   
365
+1:保持CPU 运转,屏幕和键盘灯有可能是关闭的。
366
+
367
+参数2 string tag
368
+
369
+~~~
370
+keep.setWakeLock(1,"tag");
371
+~~~
372
+
373
+### 唤醒cpu  需先设置唤醒cpu 类型(安卓有效,ios 无功能)
374
+#### acquire
375
+参数1 number 时间
376
+
377
+~~~
378
+keep.acquire(-1);
379
+~~~
380
+### 释放cpu  需先设置唤醒cpu 类型(安卓有效,ios 无功能)
381
+####  releaseAcquire
382
+~~~
383
+keep.releaseAcquire();
384
+~~~
385
+
386
+
387
+### 后台背景音乐测试  启动保活之前调用 (安卓有效,ios 无功能)
388
+~~~
389
+keep.setMusicVol(0) // 0~1 范围
390
+keep.setMusicId("music")   // 将音乐放进  插件目录 /res/raw/music.mp3  
391
+~~~
392
+
393
+### 主动退出应用后台运行,相当于单击home (安卓有效,ios 无功能)
394
+~~~
395
+keep.toBackground();
396
+~~~
397
+
398
+
399
+### android 息屏准确执行定时器  (二者选择一个就可)
400
+
401
+#### 定时器1   android/iOS/ web 三端均可用无需判断平台
402
+~~~
403
+//开启定时器     60时间为秒
404
+ keep.onStartCSystemTimer(60,function(){
405
+	console.log("onStartCSystemTimer ")
406
+});
407
+	
408
+//keep.cancelCSystemTimer();// 取消定时器
409
+//keep.clearAllCTimer();  // 取消全部定时器
410
+~~~
411
+
412
+
413
+
414
+
415
+#### 定时器2 
416
+~~~
417
+// android 原生定时任何状态一秒误差, 开始时间 1000为1秒0是马上执行, 开启周期 65*1000, 循环时间 大于60s 精准有效 低于60秒偏差误差
418
+ keep.startAleraTask(0,65*1000,function(){
419
+   	console.log("onAleraTaskListener ")
420
+ }); 
421
+     
422
+   	//取消循环定时
423
+keep.cancleAleraTask()
424
+~~~
425
+
426
+
427
+<!-- #### 定时器3 (待测试) 推荐  android/iOS/ web 微信小程序四端可用无需判断平台
428
+~~~
429
+//开启定时器     3时间为秒
430
+ keep.startKeepClcokTimer(3,function(){
431
+	console.log("startCSystemTimer ")
432
+});
433
+	
434
+//keep.cancelKeepClcokTimer();// 取消定时器
435
+//keep.cancelAllKeepClcokTimer();  // 取消全部定时器
436
+~~~ -->
437
+
438
+### 获取插件存活时间
439
+~~~
440
+var liveTime=keep.getLiveTime();// 毫秒时间
441
+~~~
442
+
443
+
444
+### 隐藏最近任务(安卓有效,ios 无功能)
445
+参数1  boolean   true 为隐藏,false为显示
446
+~~~
447
+keep.hideRecentTask(true);// 隐藏
448
+~~~
449
+### 打开安卓系统应用设置 方便用户设置自启动(安卓有效,ios 无功能)
450
+~~~
451
+keep.goAndroidSystemAppSetting();
452
+~~~
453
+### 崩溃后重启 (原生Rom 有效 )
454
+~~~
455
+keep.setCrashRestartUIEnabled(true);
456
+~~~
457
+
458
+
459
+### 其它功能
460
+~~~
461
+android channel 为android通知栏通配置
462
+对使用插件app的新用户
463
+本插件的channelId 默认为keeplive channelName 默认为keeplive  默认为有声通知。首次调用keep.register()/keep.updateNotification() 这个channel 就会自定创建好,并且不可修改
464
+本插件可自定义channel 在调用keep.register()/keep.updateNotification()之前调用下面代码
465
+keep.setNotifaicationSoundEnable(false);
466
+keep.setChannelId("保活");
467
+keep.setChannelName("保活") //通知名称
468
+keep.register();//keep.updateNotification()/* 同样为调用即为创建,之后不可修改,但是可以添加新的, 调用其中一个即可,之后就一直按照新的配置发送通知*/
469
+
470
+~~~
471
+
472
+### 安卓部分手机wifi状态下,休眠的时候 wifi 会断开连接,可以调用下面的代码 使休眠的时候保持wifi 连接
473
+~~~
474
+keep.wifilock();// 休眠时锁定wifi
475
+
476
+~~~
477
+~~~
478
+keep.wifiunlock();// 休眠时取消锁定wifi
479
+~~~
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+

+ 6 - 0
uni_modules/android-keeplive/utssdk/app-android/config.json

@@ -0,0 +1,6 @@
1
+{
2
+  "minSdkVersion": "19",
3
+  "dependencies": [
4
+	  "androidx.work:work-runtime:2.7.1"
5
+  ]
6
+}

BIN
uni_modules/android-keeplive/utssdk/app-android/index.uts


BIN
uni_modules/android-keeplive/utssdk/app-android/libs/cactus-release.aar


BIN
uni_modules/android-keeplive/utssdk/app-android/res/drawable/icon.png


+ 91 - 0
uni_modules/android-keeplive/utssdk/app-harmony/ForegroundService.ets

@@ -0,0 +1,91 @@
1
+import { ServiceExtensionAbility, Want } from '@ohos.ability.ServiceExtensionAbility';
2
+import { NotificationManager } from '@ohos.notificationManager';
3
+import { BusinessError } from '@ohos.base';
4
+
5
+export default class ForegroundService extends ServiceExtensionAbility {
6
+  onCreate(want: Want) {
7
+    super.onCreate(want);
8
+    // 初始化通知
9
+    this.initNotification(want.parameters?.notificationTitle, want.parameters?.notificationContent);
10
+  }
11
+
12
+  initNotification(title: string, content: string) {
13
+    const notificationRequest: NotificationManager.NotificationRequest = {
14
+      id: 1,
15
+      slotType: NotificationManager.SlotType.SERVICE_INFORMATION,
16
+      content: {
17
+        contentType: NotificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
18
+        normal: {
19
+          title: title || '服务运行中',
20
+          text: content || '服务正在运行,更新中...',
21
+          additionalText: ''
22
+        }
23
+      },
24
+      wantAgent: {
25
+        want: {
26
+          bundleName: 'com.example.myapp',
27
+          abilityName: 'EntryAbility'
28
+        }
29
+      }
30
+    };
31
+
32
+    NotificationManager.publish(notificationRequest, (err: BusinessError) => {
33
+      if (err) {
34
+        console.error(`Failed to publish notification. Code is ${err.code}, message is ${err.message}`);
35
+        return;
36
+      }
37
+      console.info('Succeeded in publishing notification.');
38
+    });
39
+  }
40
+
41
+  // 更新通知栏内容
42
+  updateNotification(title: string, content: string) {
43
+    const notificationRequest: NotificationManager.NotificationRequest = {
44
+      id: 1,
45
+      slotType: NotificationManager.SlotType.SERVICE_INFORMATION,
46
+      content: {
47
+        contentType: NotificationManager.ContentType.NOTIFICATION_CONTENT_BASIC_TEXT,
48
+        normal: {
49
+          title: title,
50
+          text: content,
51
+          additionalText: ''
52
+        }
53
+      },
54
+      wantAgent: {
55
+        want: {
56
+          bundleName: 'com.example.myapp',
57
+          abilityName: 'EntryAbility'
58
+        }
59
+      }
60
+    };
61
+
62
+    NotificationManager.publish(notificationRequest, (err: BusinessError) => {
63
+      if (err) {
64
+        console.error(`Failed to update notification. Code is ${err.code}, message is ${err.message}`);
65
+        return;
66
+      }
67
+      console.info('Succeeded in updating notification.');
68
+    });
69
+  }
70
+
71
+  // 保活逻辑
72
+  onForeground() {
73
+    // 这里可以添加保活逻辑,例如定时更新通知
74
+    setInterval(() => {
75
+    //  this.updateNotification('服务运行中', '服务正在运行,更新中...');
76
+    }, 60 * 1000); // 每分钟更新一次
77
+  }
78
+
79
+  // 服务销毁时的清理逻辑
80
+  onDestroy() {
81
+    super.onDestroy();
82
+    // 取消通知
83
+    NotificationManager.cancel(1, (err: BusinessError) => {
84
+      if (err) {
85
+        console.error(`Failed to cancel notification. Code is ${err.code}, message is ${err.message}`);
86
+        return;
87
+      }
88
+      console.info('Succeeded in canceling notification.');
89
+    });
90
+  }
91
+}

+ 100 - 0
uni_modules/android-keeplive/utssdk/app-harmony/ServiceManager.ets

@@ -0,0 +1,100 @@
1
+
2
+import { startAbility, stopAbility } from '@ohos.ability.featureAbility';
3
+import { NotificationManager } from '@ohos.notificationManager';
4
+import { BusinessError } from '@ohos.base';
5
+import { Want } from '@kit.AbilityKit';
6
+
7
+export class ServiceManager {
8
+  private static instance: ServiceManager;
9
+
10
+  private constructor() {}
11
+
12
+  public static getInstance(): ServiceManager {
13
+    if (!ServiceManager.instance) {
14
+      ServiceManager.instance = new ServiceManager();
15
+    }
16
+    return ServiceManager.instance;
17
+  }
18
+
19
+  // 启动服务并指定通知标题和内容
20
+  startService(notificationTitle: string, notificationContent: string) {
21
+    const want: Want = {
22
+      bundleName: 'com.example.myapp',
23
+      abilityName: 'MyService',
24
+      parameters: {
25
+        notificationTitle: notificationTitle,
26
+        notificationContent: notificationContent
27
+      }
28
+    };
29
+
30
+    startAbility(want, (err: BusinessError) => {
31
+      if (err) {
32
+        console.error(`Failed to start service. Code is ${err.code}, message is ${err.message}`);
33
+        return;
34
+      }
35
+      console.info('Succeeded in starting service.');
36
+    });
37
+  }
38
+
39
+  // 关闭服务
40
+  stopService() {
41
+    const want: Want = {
42
+      bundleName: 'com.example.myapp',
43
+      abilityName: 'MyService'
44
+    };
45
+
46
+    stopAbility(want, (err: BusinessError) => {
47
+      if (err) {
48
+        console.error(`Failed to stop service. Code is ${err.code}, message is ${err.message}`);
49
+        return;
50
+      }
51
+      console.info('Succeeded in stopping service.');
52
+    });
53
+  }
54
+
55
+  // 检测通知权限
56
+  checkNotificationPermission() {
57
+    return new Promise<boolean>((resolve, reject) => {
58
+      NotificationManager.isNotificationEnabled((err: BusinessError, isEnabled: boolean) => {
59
+        if (err) {
60
+          reject(err);
61
+        } else {
62
+          resolve(isEnabled);
63
+        }
64
+      });
65
+    });
66
+  }
67
+
68
+  // 申请通知权限
69
+  requestNotificationPermission() {
70
+    return new Promise<void>((resolve, reject) => {
71
+      NotificationManager.requestEnableNotification((err: BusinessError) => {
72
+        if (err) {
73
+          reject(err);
74
+        } else {
75
+          resolve();
76
+        }
77
+      });
78
+    });
79
+  }
80
+
81
+  // 更新通知内容和标题
82
+  updateNotification(notificationTitle: string, notificationContent: string) {
83
+    const want: Want = {
84
+      bundleName: 'com.example.myapp',
85
+      abilityName: 'MyService',
86
+      parameters: {
87
+        notificationTitle: notificationTitle,
88
+        notificationContent: notificationContent
89
+      }
90
+    };
91
+
92
+    startAbility(want, (err: BusinessError) => {
93
+      if (err) {
94
+        console.error(`Failed to update notification. Code is ${err.code}, message is ${err.message}`);
95
+        return;
96
+      }
97
+      console.info('Succeeded in updating notification.');
98
+    });
99
+  }
100
+}

BIN
uni_modules/android-keeplive/utssdk/app-harmony/index.uts


+ 20 - 0
uni_modules/android-keeplive/utssdk/app-harmony/module.json5

@@ -0,0 +1,20 @@
1
+{
2
+  "module": {
3
+    "name": "uni_modules__android_keeplive",
4
+    "type": "har",
5
+    "deviceTypes": [
6
+      "default",
7
+      "tablet",
8
+      "2in1"
9
+    ],
10
+    "requestPermissions": [
11
+		{
12
+		  "name": "ohos.permission.KEEP_BACKGROUND_RUNNING",
13
+		  "reason": "$string:Harmony_keep_permission_reason",
14
+		  "usedScene": {
15
+		    "when": "always"
16
+		  }
17
+		}
18
+    ]
19
+  }
20
+}

+ 20 - 0
uni_modules/android-keeplive/utssdk/app-harmony/resources/base/element/string.json

@@ -0,0 +1,20 @@
1
+{
2
+  "string": [
3
+	{
4
+      "name": "Harmony_location_permission_reason",
5
+      "value": "获取位置信息需要访问定位权限"
6
+    },
7
+	{
8
+	  "name": "Harmony_net_permission_reason",
9
+	  "value": "获取位置信息需要访问网络权限"
10
+	},{
11
+	  "name": "Harmony_keep_permission_reason",
12
+	  "value": "需要后台运行以获取权限"
13
+	},
14
+	{
15
+	  "name": "Harmony_notification_permission_reason",
16
+	  "value": "用于发送通知"
17
+	}
18
+	
19
+  ]
20
+}

BIN
uni_modules/android-keeplive/utssdk/app-ios/KeepLive.swift


BIN
uni_modules/android-keeplive/utssdk/app-ios/Resources/main.mp3


+ 3 - 0
uni_modules/android-keeplive/utssdk/app-ios/config.json

@@ -0,0 +1,3 @@
1
+{
2
+  "deploymentTarget": "12"
3
+}

BIN
uni_modules/android-keeplive/utssdk/app-ios/index.uts


+ 18 - 0
uni_modules/android-keeplive/utssdk/app-ios/info.plist

@@ -0,0 +1,18 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+<plist version="1.0">
4
+  <dict>
5
+	<!-- 后台模式声明 -->
6
+	<key>UIBackgroundModes</key>
7
+	<array>
8
+	    <string>audio</string> <!-- 基础音频权限 -->
9
+		<string>fetch</string>  <!-- 后台数据获取 -->
10
+	</array>
11
+	 <key>NSUserNotificationsUsageDescription</key>
12
+	    <string>发送重要提醒和更新</string>
13
+	<!-- iOS 19+新增隐私声明 -->
14
+	<key>NSBackgroundAudioServicesEnabled</key>
15
+	<string>需要持续后台音频使应用持续运行</string>
16
+
17
+  </dict>
18
+</plist>

BIN
uni_modules/android-keeplive/utssdk/app-ios/info.zip


+ 0 - 0
uni_modules/android-keeplive/utssdk/interface.uts


+ 1 - 0
uni_modules/android-keeplive/utssdk/unierror.uts

@@ -0,0 +1 @@
1
+‡вМSћыџхVUYбА

BIN
uni_modules/android-keeplive/utssdk/utssdk.zip