diff --git a/pages/test/test.vue b/pages/test/test.vue
index e6dcd419ef9015cb0954b3afad2f0957324468f8..1c4825d882b6dc4df8065e2378108f03c3d7924d 100644
--- a/pages/test/test.vue
+++ b/pages/test/test.vue
@@ -20,7 +20,8 @@
-
+
+
@@ -28,7 +29,13 @@
@@ -321,4 +385,4 @@
font-size: 36rpx;
color: #8f8f94;
}
-
\ No newline at end of file
+
diff --git a/uni_modules/uni-exit/utssdk/app-android/index.uts b/uni_modules/uni-exit/utssdk/app-android/index.uts
index a9998120bd764e86f54ae591a187c1ab101d0ae4..6019d642b2fb52c69992da92e1543813eb898702 100644
--- a/uni_modules/uni-exit/utssdk/app-android/index.uts
+++ b/uni_modules/uni-exit/utssdk/app-android/index.uts
@@ -1,4 +1,4 @@
-import { ExitOptions, ExitSuccess, ExitCompleteCallback, Exit } from "../interface.uts"
+import { ExitOptions, ExitSuccess, Exit } from "../interface.uts"
/**
diff --git a/uni_modules/uni-exit/utssdk/app-ios/index.uts b/uni_modules/uni-exit/utssdk/app-ios/index.uts
index 3241c6768f55985371cde241a1aabb32cd904a25..5be055badece05c639c6499763ec0b26db86fd07 100644
--- a/uni_modules/uni-exit/utssdk/app-ios/index.uts
+++ b/uni_modules/uni-exit/utssdk/app-ios/index.uts
@@ -1,4 +1,4 @@
-import { ExitOptions, ExitFailCallback, ExitCompleteCallback, Exit} from "../interface.uts"
+import { ExitOptions, Exit} from "../interface.uts"
import { ExitFailImpl } from "../unierror.uts"
diff --git a/uni_modules/uni-exit/utssdk/unierror.uts b/uni_modules/uni-exit/utssdk/unierror.uts
index 93518b7aa6e45e44674619741ce706f48cf5608b..9b74feb0dce8a92485b9279bfd5c1e542d18d218 100644
--- a/uni_modules/uni-exit/utssdk/unierror.uts
+++ b/uni_modules/uni-exit/utssdk/unierror.uts
@@ -25,6 +25,7 @@ export const UniErrors:Map = new Map([
* ExitFail的实现
*/
export class ExitFailImpl extends UniError implements IExitError {
+ override errCode: ExitErrorCode
constructor (
errCode: ExitErrorCode
) {
diff --git a/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts b/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts
index ee92fecdf3bfc8006e9cae8b201420983006b6ac..f7408b505a8b786a435d142b1640f53619cb7f58 100644
--- a/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts
+++ b/uni_modules/uni-getAppBaseInfo/utssdk/interface.uts
@@ -7,7 +7,7 @@ export type GetAppBaseInfoOptions = {
export type GetAppBaseInfoResult = {
/**
- * manifest.json 中应用appid,即DCloud appid。
+ * manifest.json 中应用appid,即DCloud appid。
*/
appId?: string,
/**
@@ -23,11 +23,11 @@ export type GetAppBaseInfoResult = {
*/
appVersionCode?: string,
/**
- * 应用设置的语言en、zh-Hans、zh-Hant、fr、es
+ * 应用设置的语言en、zh-Hans、zh-Hant、fr、es
*/
appLanguage?: string,
/**
- * 应用设置的语言
+ * 应用设置的语言
*/
language?: string,
/**
@@ -36,8 +36,8 @@ export type GetAppBaseInfoResult = {
*/
version?: string,
/**
- * 应用资源(wgt)的版本名称。
- *
+ * 应用资源(wgt)的版本名称。
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -55,8 +55,8 @@ export type GetAppBaseInfoResult = {
*/
appWgtVersion?: string,
/**
- * 小程序宿主语言
- *
+ * 小程序宿主语言
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -75,7 +75,7 @@ export type GetAppBaseInfoResult = {
hostLanguage?: string,
/**
* App、小程序宿主版本。
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -93,8 +93,8 @@ export type GetAppBaseInfoResult = {
*/
hostVersion?: string,
/**
- * 小程序宿主名称
- *
+ * 小程序宿主名称
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -112,8 +112,8 @@ export type GetAppBaseInfoResult = {
*/
hostName?: string,
/**
- * 小程序宿主包名
- *
+ * 小程序宿主包名
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -131,8 +131,8 @@ export type GetAppBaseInfoResult = {
*/
hostPackageName?: string,
/**
- * uni小程序SDK版本、小程序客户端基础库版本
- *
+ * uni小程序SDK版本、小程序客户端基础库版本
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -151,7 +151,7 @@ export type GetAppBaseInfoResult = {
hostSDKVersion?: string,
/**
* 系统当前主题,取值为light或dark。微信小程序全局配置"darkmode":true时才能获取,否则为 undefined (不支持小游戏)
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -203,7 +203,7 @@ export type GetAppBaseInfo = (options?: GetAppBaseInfoOptions | null) => GetAppB
export interface Uni {
/**
* GetAppBaseInfo(Object object)
- * @description
+ * @description
* 获取app基本信息
* @param {GetAppBaseInfoOptions} options [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。
* @return {object}
@@ -218,7 +218,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9+"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts
index 10f846a857d9b241cac3642a8d3a7d082128f07a..cb6f7e2178d68121f30ea05c89934494b099b946 100644
--- a/uni_modules/uni-getDeviceInfo/utssdk/interface.uts
+++ b/uni_modules/uni-getDeviceInfo/utssdk/interface.uts
@@ -19,36 +19,36 @@ export type GetDeviceInfoResult = {
*/
deviceId?: string,
/**
- * 设备型号
+ * 设备型号
*/
model?: string,
/**
- * 设备型号
+ * 设备型号
*/
deviceModel?: string,
/**
- * 设备类型phone、pad、pc
+ * 设备类型phone、pad、pc
*/
deviceType?: string,
/**
- * 设备方向 竖屏 portrait、横屏 landscape
+ * 设备方向 竖屏 portrait、横屏 landscape
*/
deviceOrientation?: string,
/**
- * 设备像素比
+ * 设备像素比
*/
devicePixelRatio?: string,
/**
- * 操作系统及版本
+ * 操作系统及版本
*/
system?: string,
/**
- * 客户端平台
+ * 客户端平台
*/
platform?: string,
/**
* oaid标识 Android专有
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -75,7 +75,7 @@ export type GetDeviceInfoResult = {
isSimulator?: boolean,
/**
* adb是否开启
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -94,7 +94,7 @@ export type GetDeviceInfoResult = {
isUSBDebugging?: boolean,
/**
* idfa标识 iOS专有
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -105,7 +105,7 @@ export type GetDeviceInfoResult = {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "√"
+ * "unixVer": "x"
* }
* }
* }
@@ -126,7 +126,7 @@ export type GetDeviceInfo = (options?: GetDeviceInfoOptions | null) => GetDevice
export interface Uni {
/**
* GetDeviceInfo(Object object)
- * @description
+ * @description
* 获取设备信息
* @param {GetDeviceInfoOptions} options [options=包含所有字段的过滤对象] 过滤的字段对象, 不传参数默认为获取全部字段。
* @return {object}
@@ -141,7 +141,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9+"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-getSystemSetting/utssdk/interface.uts b/uni_modules/uni-getSystemSetting/utssdk/interface.uts
index 954e4cba0409af160293de3b0f5a9ef944fc9670..ed1460cb0d44b0a7c08653f212b9541bd98c4c79 100644
--- a/uni_modules/uni-getSystemSetting/utssdk/interface.uts
+++ b/uni_modules/uni-getSystemSetting/utssdk/interface.uts
@@ -34,7 +34,7 @@ export type GetSystemSetting = () => GetSystemSettingResult
export interface Uni {
/**
* GetSystemSetting()
- * @description
+ * @description
* 获取系统设置
* @return {object}
* @tutorial https://uniapp.dcloud.net.cn/api/system/getsystemsetting.html
@@ -48,7 +48,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9+"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts
index 214180b1fd9c777eafd021fba91cea0351a48950..79130b5dac27150d68fbf533ab06186612d70975 100644
--- a/uni_modules/uni-getbatteryinfo/utssdk/interface.uts
+++ b/uni_modules/uni-getbatteryinfo/utssdk/interface.uts
@@ -91,7 +91,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.6.11",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -118,7 +118,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.6.11",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-installApk/changelog.md b/uni_modules/uni-installApk/changelog.md
index f6c958315f645b5da63f7296755c1493e57d5c20..d67eb701ef976498949ebb5d5eec4b9531e0834e 100644
--- a/uni_modules/uni-installApk/changelog.md
+++ b/uni_modules/uni-installApk/changelog.md
@@ -1,3 +1,5 @@
+## 1.0.4(2023-12-08)
+兼容asset目录文件的处理
## 1.0.3(2023-10-27)
遵循UniError规范
## 1.0.2(2023-10-27)
diff --git a/uni_modules/uni-installApk/package.json b/uni_modules/uni-installApk/package.json
index c3889207923f11964792eb3bd7659e39427e6ab8..2270fe2ab7e79516176a637fa9536ccfc1a60111 100644
--- a/uni_modules/uni-installApk/package.json
+++ b/uni_modules/uni-installApk/package.json
@@ -1,7 +1,7 @@
{
"id": "uni-installApk",
"displayName": "uni-installApk",
- "version": "1.0.3",
+ "version": "1.0.4",
"description": "uni-installApk",
"keywords": [
"uni-installApk"
diff --git a/uni_modules/uni-installApk/utssdk/app-android/index.uts b/uni_modules/uni-installApk/utssdk/app-android/index.uts
index cfdef2ed5ce2368b42ad73e9152d2dadf2ddc9cb..64e7b6bdc7698fee1d7ddce32329aede1e619ed7 100644
--- a/uni_modules/uni-installApk/utssdk/app-android/index.uts
+++ b/uni_modules/uni-installApk/utssdk/app-android/index.uts
@@ -1,4 +1,4 @@
-import { InstallApkOptions, InstallApkSuccess } from "../interface.uts"
+import { InstallApkOptions, InstallApkSuccess } from "../interface.uts"
import { InstallApkFailImpl } from "../unierror.uts"
import Intent from 'android.content.Intent';
import Build from 'android.os.Build';
@@ -6,34 +6,78 @@ import File from 'java.io.File';
import FileProvider from 'androidx.core.content.FileProvider';
import Context from 'android.content.Context';
import Uri from 'android.net.Uri';
+import FileOutputStream from 'java.io.FileOutputStream';
export function installApk(options : InstallApkOptions) : void {
- const context = UTSAndroid.getAppContext() as Context
- const filePath = UTSAndroid.convert2AbsFullPath(options.filePath)
- const apkFile = new File(filePath)
- if (!apkFile.exists() && !apkFile.isFile()) {
- let error = new InstallApkFailImpl(1300002);
- options.fail?.(error)
- options.complete?.(error)
- return
- }
- const intent = new Intent()
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- intent.setAction(Intent.ACTION_VIEW)
-
- if (Build.VERSION.SDK_INT >= 24) {
- const authority = context.getPackageName() + ".dc.fileprovider"
- const apkUri = FileProvider.getUriForFile(context, authority, apkFile)
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
- } else {
- intent.setDataAndType(Uri.fromFile(apkFile), "application/vnd.android.package-archive");
- }
-
- context.startActivity(intent)
- const success : InstallApkSuccess = {
- errMsg: "success"
- }
- options.success?.(success)
- options.complete?.(success)
-}
\ No newline at end of file
+ const context = UTSAndroid.getAppContext() as Context
+ var filePath = UTSAndroid.convert2AbsFullPath(options.filePath)
+ var apkFile : File | null = null;
+ if (filePath.startsWith("/android_asset/")) {
+ filePath = filePath.replace("/android_asset/", "")
+ apkFile = copyAssetFileToPrivateDir(context, filePath)
+ } else {
+ apkFile = new File(filePath)
+ }
+
+ if (apkFile != null && !apkFile.exists() && !apkFile.isFile()) {
+ let error = new InstallApkFailImpl(1300002);
+ options.fail?.(error)
+ options.complete?.(error)
+ return
+ }
+ const intent = new Intent()
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ intent.setAction(Intent.ACTION_VIEW)
+
+ if (Build.VERSION.SDK_INT >= 24) {
+ const authority = context.getPackageName() + ".dc.fileprovider"
+ const apkUri = FileProvider.getUriForFile(context, authority, apkFile!!)
+ intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
+ intent.setDataAndType(apkUri, "application/vnd.android.package-archive");
+ } else {
+ intent.setDataAndType(Uri.fromFile(apkFile!!), "application/vnd.android.package-archive");
+ }
+
+ context.startActivity(intent)
+ const success : InstallApkSuccess = {
+ errMsg: "success"
+ }
+ options.success?.(success)
+ options.complete?.(success)
+}
+
+
+function copyAssetFileToPrivateDir(context : Context, fileName : string) : File | null {
+ try {
+ const destPath = context.getCacheDir().getPath() + "/apks/" + fileName
+ const outFile = new File(destPath)
+ const parentFile = outFile.getParentFile()
+ if (parentFile != null) {
+ if (!parentFile.exists()) {
+ parentFile.mkdirs()
+ }
+ }
+ if (!outFile.exists()) {
+ outFile.createNewFile()
+ }
+ const inputStream = context.getAssets().open(fileName)
+ const outputStream = new FileOutputStream(outFile)
+ let buffer = new ByteArray(1024);
+ do {
+ let len = inputStream.read(buffer);
+ if (len == -1) {
+ break;
+ }
+ outputStream.write(buffer, 0, len)
+ } while (true)
+
+ inputStream.close()
+ outputStream.close()
+
+ return outFile
+ } catch (e : Exception) {
+ e.printStackTrace()
+ }
+
+ return null
+}
diff --git a/uni_modules/uni-installApk/utssdk/index.d.ts b/uni_modules/uni-installApk/utssdk/index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..ad24effbc1e07f4f30aa894e39cb3d388350dabe
--- /dev/null
+++ b/uni_modules/uni-installApk/utssdk/index.d.ts
@@ -0,0 +1,78 @@
+declare namespace UniNamespace {
+
+interface InstallApkSuccess {
+ /**
+ * 安装成功消息
+ */
+ errMsg : string
+}
+
+type InstallApkErrorCode = 1300002
+interface InstallApkFail {
+ errCode : InstallApkErrorCode
+}
+
+type InstallApkComplete = any
+
+type InstallApkSuccessCallback = (res : InstallApkSuccess) => void
+type InstallApkFailCallback = (err : InstallApkFail) => void
+type InstallApkCompleteCallback = (res : InstallApkComplete) => void
+
+interface InstallApkOptions {
+ /**
+ * apk文件地址
+ */
+ filePath : string,
+ /**
+ * 接口调用成功的回调函数
+ * @defaultValue null
+ */
+ success ?: InstallApkSuccessCallback | null,
+ /**
+ * 接口调用失败的回调函数
+ * @defaultValue null
+ */
+ fail ?: InstallApkFailCallback | null,
+ /**
+ * 接口调用结束的回调函数(调用成功、失败都会执行)
+ * @defaultValue null
+ */
+ complete ?: InstallApkCompleteCallback | null
+}
+
+}
+
+
+declare interface Uni {
+ /**
+ * installApk()
+ * @description
+ * 安装apk
+ * @param {InstallApkOptions}
+ * @return {void}
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "3.94+",
+ * "unixVer": "3.94+"
+ * },
+ * "ios": {
+ * "osVer": "x",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ uni.installApk({
+ filePath: "/xx/xx/xx.apk",
+ complete: (res: any) => {
+ console.log("complete => " + JSON.stringify(res));
+ }
+ });
+ ```
+ */
+ installApk(options : UniNamespace.InstallApkOptions) : void
+}
diff --git a/uni_modules/uni-memorywarning/utssdk/app-android/index.uts b/uni_modules/uni-memorywarning/utssdk/app-android/index.uts
index 28bf366a9359e188f6f53ea5bba905746b8a192c..ec4a9106ec63f5468ba459e4566fe23449865f03 100644
--- a/uni_modules/uni-memorywarning/utssdk/app-android/index.uts
+++ b/uni_modules/uni-memorywarning/utssdk/app-android/index.uts
@@ -1,20 +1,20 @@
import { UTSAndroid } from "io.dcloud.uts"
-import { OnMemoryWarning, OffMemoryWarning } from "../interface.uts"
+import { OnMemoryWarning, OffMemoryWarning, MemoryWarningCallback, MemoryWarningCallbackResult } from "../interface.uts"
-let listeners: UTSCallback[] = []
+let listeners: MemoryWarningCallback[] = []
const onAppTrimMemoryListener = (ret: number) => {
listeners.forEach(listener => {
- let res = {
- level:ret
- }
- listener(res)
+ let res: MemoryWarningCallbackResult = {
+ level:ret
+ }
+ listener(res)
})
}
@Suppress("DEPRECATION")
-export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) {
+export const onMemoryWarning : OnMemoryWarning = function (callback: MemoryWarningCallback) {
if (listeners.length == 0) {
// 仅首次执行底层的实际监听
UTSAndroid.onAppTrimMemory(onAppTrimMemoryListener)
@@ -28,7 +28,7 @@ export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallbac
@Suppress("DEPRECATION")
-export const offMemoryWarning : OffMemoryWarning = function (callback: UTSCallback | null) {
+export const offMemoryWarning : OffMemoryWarning = function (callback: MemoryWarningCallback | null) {
if(callback == null){
// 清除全部回调
diff --git a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts
index 60ee47f5749bf69643f221b9d3ac18f7badaa9f1..5f4f37bfdc3f0e3bf20a5c98d9a90852b1b0171b 100644
--- a/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts
+++ b/uni_modules/uni-memorywarning/utssdk/app-ios/index.uts
@@ -1,58 +1,47 @@
import { NotificationCenter } from 'Foundation';
import { UIApplication } from "UIKit"
import { Selector } from "ObjectiveC"
-import { OnMemoryWarning, OffMemoryWarning } from "../interface.uts"
+import { OnMemoryWarning, OffMemoryWarning, MemoryWarningCallback, MemoryWarningCallbackResult } from "../interface.uts"
class MemoryWarningTool {
- static listeners: UTSCallback[] = []
-
+ static listener: MemoryWarningCallback | null = null
// 监听内存警告
- static listenMemoryWarning(callback: UTSCallback) {
-
+ static listenMemoryWarning(callback: MemoryWarningCallback) {
+
// 只有首次才需要注册监听事件
- if (this.listeners.length == 0) {
+ if (this.listener == null) {
// 注册监听内存警告通知事件及设置回调方法
// target-action 回调方法需要通过 Selector("方法名") 构建
const method = Selector("receiveMemoryWarning")
NotificationCenter.default.addObserver(this, selector = method, name = UIApplication.didReceiveMemoryWarningNotification, object = null)
}
- this.listeners.push(callback)
+ this.listener = callback
}
-
+
// 内存警告回调的方法
// target-action 的方法前需要添加 @objc 前缀
@objc static receiveMemoryWarning() {
// 触发回调
- this.listeners.forEach(listener => {
- listener({})
- })
+ let res: MemoryWarningCallbackResult = {
+ level: 0
+ };
+ this.listener?.(res);
}
-
+
// 移除监听事件
- static removeListen(callback: UTSCallback | null) {
- // 移除所有监听
- if (callback == null) {
- this.listeners = []
- // 移除监听事件
- NotificationCenter.default.removeObserver(this)
- return
- }
-
- // 清除指定回调
- const index = this.listeners.indexOf(callback!)
- if (index > -1) {
- this.listeners.splice(index, 1)
- }
+ static removeListen(callback: MemoryWarningCallback | null) {
+ this.listener = null;
+ NotificationCenter.default.removeObserver(this)
}
}
// 开启监听内存警告
-export const onMemoryWarning : OnMemoryWarning = function (callback: UTSCallback) {
+export const onMemoryWarning : OnMemoryWarning = function (callback: MemoryWarningCallback) {
MemoryWarningTool.listenMemoryWarning(callback)
}
// 关闭监听内存警告
-export const offMemoryWarning : OffMemoryWarning = function (callback: UTSCallback | null) {
+export const offMemoryWarning : OffMemoryWarning = function (callback: MemoryWarningCallback | null) {
MemoryWarningTool.removeListen(callback)
-}
\ No newline at end of file
+}
diff --git a/uni_modules/uni-memorywarning/utssdk/index.d.ts b/uni_modules/uni-memorywarning/utssdk/index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..fbad2381541932af0d66eb7abc0bfb22bbdb1d36
--- /dev/null
+++ b/uni_modules/uni-memorywarning/utssdk/index.d.ts
@@ -0,0 +1,71 @@
+declare namespace UniNamespace {
+
+interface MemoryWarningCallbackResult {
+ /**
+ * 内存警告等级(仅安卓平台有效,iOS始终是0)
+ */
+ level: number
+}
+
+/**
+ * uni.onMemoryWarning/uni.offMemoryWarning回调函数定义
+ */
+type MemoryWarningCallback = (res: MemoryWarningCallbackResult) => void
+
+type OnMemoryWarning = (callback: MemoryWarningCallback) => void
+
+type OffMemoryWarning = (callback : MemoryWarningCallback | null) => void
+
+}
+
+
+declare interface Uni {
+ /**
+ * 开启监听内存警告
+ *
+ * @param {MemoryWarningCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#onmemorywarning
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ onMemoryWarning(callback: UniNamespace.MemoryWarningCallback) : void,
+ /**
+ * 取消监听内存不足告警事件
+ *
+ * @param {MemoryWarningCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#offmemorywarning
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ offMemoryWarning(callback : UniNamespace.MemoryWarningCallback | null) : void
+}
diff --git a/uni_modules/uni-memorywarning/utssdk/interface.uts b/uni_modules/uni-memorywarning/utssdk/interface.uts
index 5e11ec45b24fb0ba56d204fc2a9eab50d255b807..1e3250e8dbf5da28517666206eae16748871dd28 100644
--- a/uni_modules/uni-memorywarning/utssdk/interface.uts
+++ b/uni_modules/uni-memorywarning/utssdk/interface.uts
@@ -1,13 +1,27 @@
+/**
+ * uni.onMemoryWarning/uni.offMemoryWarning回调参数
+ */
+export type MemoryWarningCallbackResult = {
+ /**
+ * 内存警告等级(仅安卓平台有效,iOS始终是0)
+ */
+ level: number
+}
-export type OnMemoryWarning = (callback: UTSCallback) => void
+/**
+ * uni.onMemoryWarning/uni.offMemoryWarning回调函数定义
+ */
+export type MemoryWarningCallback = (res: MemoryWarningCallbackResult) => void
+
+export type OnMemoryWarning = (callback: MemoryWarningCallback) => void
-export type OffMemoryWarning = (callback : UTSCallback | null) => void
+export type OffMemoryWarning = (callback : MemoryWarningCallback | null) => void
export interface Uni {
/**
* 开启监听内存警告
- *
- * @param {UTSCallback} callback
+ *
+ * @param {MemoryWarningCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#onmemorywarning
* @uniPlatform {
* "app": {
@@ -19,7 +33,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -27,11 +41,11 @@ export interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
- onMemoryWarning(callback: UTSCallback) : void,
+ onMemoryWarning(callback: MemoryWarningCallback) : void,
/**
* 取消监听内存不足告警事件
- *
- * @param {UTSCallback} callback
+ *
+ * @param {MemoryWarningCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/memory.html#offmemorywarning
* @uniPlatform {
* "app": {
@@ -43,7 +57,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -51,5 +65,5 @@ export interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
- offMemoryWarning(callback : UTSCallback | null) : void
-}
\ No newline at end of file
+ offMemoryWarning(callback : MemoryWarningCallback | null) : void
+}
diff --git a/uni_modules/uni-network/utssdk/interface.uts b/uni_modules/uni-network/utssdk/interface.uts
index 8aa400b813e6a110083012e5496a5ce675834608..8c194d33413e08924b9110684dff069e7273028f 100644
--- a/uni_modules/uni-network/utssdk/interface.uts
+++ b/uni_modules/uni-network/utssdk/interface.uts
@@ -40,21 +40,21 @@ export type RequestOptions = {
dataType?: string | null,
/**
* 设置响应的数据类型。
- *
+ *
* @deprecated 不支持
* @autodoc false
*/
responseType?: string | null,
/**
* 验证 ssl 证书
- *
+ *
* @deprecated 不支持
* @autodoc false
*/
sslVerify?: boolean | null,
/**
* 跨域请求时是否携带凭证(cookies)
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -69,7 +69,7 @@ export type RequestOptions = {
* }
* }
* }
- *
+ *
*/
withCredentials?: boolean | null,
/**
@@ -121,7 +121,7 @@ export type RequestSuccess = {
* - PUT PUT方法用有效载荷请求替换目标资源的所有当前表示。
* - PATCH PATCH方法用于对资源应用部分修改。
* - DELETE DELETE方法删除指定的资源。
- * - HEAD HEAD方法请求一个与GET请求的响应相同的响应,但没有响应体。
+ * - HEAD HEAD方法请求一个与GET请求的响应相同的响应,但没有响应体。
* - OPTIONS OPTIONS 方法用于描述目标资源的通信选项。
*/
export type RequestMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
@@ -153,9 +153,9 @@ export type RequestCompleteCallback = (option: any) => void;
export interface RequestTask {
/**
* abort()
- * @description
+ * @description
* 中断网络请求。
- * @param {void}
+ * @param {void}
* @return {void}
* @tutorial https://uniapp.dcloud.net.cn/api/request/request.html#request
* @uniPlatform {
@@ -168,7 +168,7 @@ export interface RequestTask {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9+"
+ * "unixVer": "x"
* }
* }
* }
@@ -307,9 +307,9 @@ export type UploadFileProgressUpdateCallback = (result: OnProgressUpdateResult)
export interface UploadTask {
/**
* abort()
- * @description
+ * @description
* 中断上传任务。
- * @param {void}
+ * @param {void}
* @return {void}
* @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#uploadfile
* @uniPlatform {
@@ -338,7 +338,7 @@ export interface UploadTask {
abort(): void,
/**
* onProgressUpdate()
- * @description
+ * @description
* 监听上传进度变化。
* @param {UploadFileProgressUpdateCallback} callback
* @return {void}
@@ -450,9 +450,9 @@ export type DownloadFileProgressUpdateCallback = (result: OnProgressDownloadResu
export interface DownloadTask {
/**
* abort()
- * @description
+ * @description
* 中断下载任务。
- * @param {void}
+ * @param {void}
* @return {void}
* @tutorial https://uniapp.dcloud.net.cn/api/request/network-file.html#downloadfile
* @uniPlatform {
@@ -481,7 +481,7 @@ export interface DownloadTask {
abort(): void,
/**
* onProgressUpdate()
- * @description
+ * @description
* 监听下载进度变化。
* @param {DownloadFileProgressUpdateCallback} callback
* @return {void}
@@ -516,10 +516,10 @@ export interface DownloadTask {
export interface Uni {
/**
* Request()
- * @description
+ * @description
* 发起网络请求。
* @param {RequestOptions} options
- * @return {RequestTask | null}
+ * @return {RequestTask | null}
* @tutorial https://uniapp.dcloud.net.cn/api/request/request.html
* @uniPlatform {
* "app": {
@@ -531,7 +531,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9+"
+ * "unixVer": "x"
* }
* }
* }
@@ -567,7 +567,7 @@ export interface Uni {
request(param: RequestOptions): RequestTask | null;
/**
* UploadFile()
- * @description
+ * @description
* 将本地资源上传到开发者服务器。
* @param {UploadFileOptions} options
* @return {UploadTask | null}
@@ -604,7 +604,7 @@ export interface Uni {
uploadFile(options: UploadFileOptions): UploadTask | null;
/**
* DownloadFile()
- * @description
+ * @description
* 下载文件资源到本地,客户端直接发起一个 HTTP GET 请求,返回文件的本地临时路径。
* @param {DownloadFileOptions} options
* @return {DownloadTask | null}
diff --git a/uni_modules/uni-prompt/utssdk/interface.uts b/uni_modules/uni-prompt/utssdk/interface.uts
index f5e91ab0e8163ad8393424866bfca2c26ef6a18f..b37cececa856f298bb58cc1c58917737ecb72b15 100644
--- a/uni_modules/uni-prompt/utssdk/interface.uts
+++ b/uni_modules/uni-prompt/utssdk/interface.uts
@@ -63,9 +63,9 @@ export type ShowToastOptions = {
/**
* uni.showToast函数定义
- * 弹出toast
- *
- * @param {ShowToastOptions} options
+ * 弹出toast
+ *
+ * @param {ShowToastOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#showtoast
* @uniPlatform {
* "app": {
@@ -77,7 +77,7 @@ export type ShowToastOptions = {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -87,7 +87,7 @@ export type ShowToast = (options: ShowToastOptions) => void
/**
* uni.hideToast函数定义
* 隐藏toast
- *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#hidetoast
* @uniPlatform {
* "app": {
@@ -99,7 +99,7 @@ export type ShowToast = (options: ShowToastOptions) => void
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -155,8 +155,8 @@ export type ShowLoadingOptions = {
/**
* uni.showLoading函数定义
* 弹出loading
- *
- * @param {ShowLoadingOptions} options
+ *
+ * @param {ShowLoadingOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#showloading
* @uniPlatform {
* "app": {
@@ -168,7 +168,7 @@ export type ShowLoadingOptions = {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -178,7 +178,7 @@ export type ShowLoading = (options: ShowLoadingOptions) => void
/**
* uni.hideLoading函数定义
* 隐藏loading
- *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#hideloading
* @uniPlatform {
* "app": {
@@ -190,11 +190,11 @@ export type ShowLoading = (options: ShowLoadingOptions) => void
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
- *
+ *
*/
export type HideLoading = () => void
@@ -286,10 +286,10 @@ export type ShowModalOptions = {
/**
* uni.showModal 函数定义
- *
+ *
* 弹出modal
- *
- * @param {ShowModalOptions} options
+ *
+ * @param {ShowModalOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#showmodal
* @uniPlatform {
* "app": {
@@ -301,7 +301,7 @@ export type ShowModalOptions = {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -390,10 +390,10 @@ export type ShowActionSheetOptions = {
/**
* uni.showActionSheet函数定义
- *
+ *
* 弹出actionSheet
- *
- * @param {ShowActionSheetOptions} options
+ *
+ * @param {ShowActionSheetOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/ui/prompt.html#showactionsheet
* @uniPlatform {
* "app": {
@@ -405,7 +405,7 @@ export type ShowActionSheetOptions = {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -438,7 +438,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -461,7 +461,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -490,7 +490,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -520,7 +520,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -556,7 +556,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -588,7 +588,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "√",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-push/changelog.md b/uni_modules/uni-push/changelog.md
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/uni_modules/uni-push/package.json b/uni_modules/uni-push/package.json
new file mode 100644
index 0000000000000000000000000000000000000000..7674d4c16b2f4a8e848dafab5f70dddf0f1e2cf3
--- /dev/null
+++ b/uni_modules/uni-push/package.json
@@ -0,0 +1,125 @@
+{
+ "id": "uni-push",
+ "displayName": "uni-push",
+ "version": "1.0.0",
+ "description": "uni-push",
+ "keywords": [
+ "uni-push"
+ ],
+ "repository": "",
+ "engines": {
+ "HBuilderX": "^3.6.8"
+ },
+ "dcloudext": {
+ "type": "uts",
+ "sale": {
+ "regular": {
+ "price": "0.00"
+ },
+ "sourcecode": {
+ "price": "0.00"
+ }
+ },
+ "contact": {
+ "qq": ""
+ },
+ "declaration": {
+ "ads": "",
+ "data": "",
+ "permissions": ""
+ },
+ "npmurl": ""
+ },
+ "uni_modules": {
+ "dependencies": [],
+ "uni-ext-api": {
+ "uni": {
+ "getPushClientId": {
+ "name": "getPushClientId",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": false
+ }
+ },
+ "onPushMessage": {
+ "name": "onPushMessage",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": false
+ }
+ },
+ "offPushMessage": {
+ "name": "offPushMessage",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": false
+ }
+ },
+ "getChannelManager": {
+ "name": "getChannelManager",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": false
+ }
+ },
+ "createPushMessage": {
+ "name": "createPushMessage",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": false
+ }
+ }
+ }
+ },
+ "encrypt": [],
+ "platforms": {
+ "cloud": {
+ "tcb": "u",
+ "aliyun": "u"
+ },
+ "client": {
+ "Vue": {
+ "vue2": "u",
+ "vue3": "u"
+ },
+ "App": {
+ "app-android": "u",
+ "app-ios": "u"
+ },
+ "H5-mobile": {
+ "Safari": "u",
+ "Android Browser": "u",
+ "微信浏览器(Android)": "u",
+ "QQ浏览器(Android)": "u"
+ },
+ "H5-pc": {
+ "Chrome": "u",
+ "IE": "u",
+ "Edge": "u",
+ "Firefox": "u",
+ "Safari": "u"
+ },
+ "小程序": {
+ "微信": "u",
+ "阿里": "u",
+ "百度": "u",
+ "字节跳动": "u",
+ "QQ": "u",
+ "钉钉": "u",
+ "快手": "u",
+ "飞书": "u",
+ "京东": "u"
+ },
+ "快应用": {
+ "华为": "u",
+ "联盟": "u"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/readme.md b/uni_modules/uni-push/readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..c5dde5d47b0ebff0c34cf361d7140765c1893b44
--- /dev/null
+++ b/uni_modules/uni-push/readme.md
@@ -0,0 +1,142 @@
+# uni-push
+
+`uni-push` 工程,是基于 DCloud-UTS 架构之上的封装个推消息推送 `SDK` 的插件工程,使用此模块可轻松实现服务端向客户端推送通知和透传消息的功能。
+
+### 插件使用说明
+
+#### 导入插件
+```uts
+import * as GTPlugin from "../../uni_modules/uni-push"
+```
+
+#### 初始化
+
+```typescript
+//初始化个推推送
+GTPlugin.initPush();
+```
+
+#### 推送消息事件
+
+> 添加透传消息回调,对应的GTPlugin.offPushMessage()可移除对应监听callback(传入null,可移除所有监听callback)
+
+```typescript
+GTPlugin.onPushMessage((res) => {
+ console.log("onPushMessage => " + JSON.stringify(res))
+})
+```
+
+| 名称 | 类型 | 描述 |
+| ---- | ------------- | ----------------------------------------------------------- |
+| type | String | 事件类型,"click"-从系统推送服务点击消息启动应用事件;"receive"-应用从推送服务器接收到推送消息事件。 |
+| data | String、Object | 消息内容 |
+
+
+
+#### 日志
+
+开发阶段,需要使用到日志辅助。
+
+```typescript
+//设置日志回调,可以在控制台看到[GT-PUSH]的日志
+GTPlugin.setDebugLogger(function(res) {
+ console.log(res)
+});
+```
+
+当插件正常初始化会出现以下日志:
+
+```uts
+16:47:53.254 [GT-PUSH] [LogController] Sdk version = 3.3.0.0 at pages/index/index.vue:25
+16:47:54.052 [GT-PUSH] [ServiceManager] ServiceManager start from initialize... at pages/index/index.vue:25
+16:47:54.073 [GT-PUSH] PushCore started at pages/index/index.vue:25
+16:47:54.274 [GT-PUSH] onHandleIntent() = get sdk service pid at pages/index/index.vue:25
+16:47:54.292 [GT-PUSH] onHandleIntent() areNotificationsEnabled at pages/index/index.vue:25
+16:47:54.353 [GT-PUSH] [LoginInteractor] Start login appid = nU*******wzf at pages/index/index.vue:25
+16:47:54.571 收到 cid onReceiveClientId : 3061f********ce7578eb24 at pages/index/index.vue:29
+16:47:54.592 [GT-PUSH] onHandleIntent() = received client id at pages/index/index.vue:25
+16:47:54.593 [GT-PUSH] [LoginResult] Login successed with cid = 3061f********ce7578eb24 at pages/index/index.vue:25
+```
+
+#### 推送相关动作
+
+> 设置推送相关动作回调,更多可查看`app-android/index.uts`下面的 `UserPushAction`类
+
+```typescript
+GTPlugin.setPushAction({
+ onReceiveClientId: function(cid) {
+ console.log("收到 cid onReceiveClientId : " + cid)
+ }
+});
+```
+
+
+
+#### 唯一的推送标识
+
+获取客户端唯一的推送标识
+
+```typescript
+GTPlugin.getPushClientId({
+ success: (res) => {
+ console.log("getPushClientId success => " + JSON.stringify(res));
+ },
+ fail: (res) => {
+ console.log("getPushClientId fail => " + JSON.stringify(res));
+ },
+ complete: (res) => {
+ console.log("getPushClientId complete => " + JSON.stringify(res));
+ }
+});
+```
+
+**OBJECT 参数说明**
+
+| 参数名 | 类型 | 必填 | 说明 |
+| -------- | -------- | --- | ------------------------ |
+| success | Function | 是 | 接口调用的回调函数,详见返回参数说明 |
+| fail | Function | 否 | 接口调用失败的回调函数 |
+| complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
+
+**success 返回参数说明**
+
+| 参数 | 类型 | 说明 |
+| ------ | ------ | ---------------------------------------- |
+| cid | String | 个推客户端推送id,对应uni-id-device表的push_clientid |
+| errMsg | String | 错误描述 |
+
+**fail 返回参数说明**
+
+| 参数 | 类型 | 说明 |
+| ------ | ------ | ---- |
+| errMsg | String | 错误描述 |
+
+
+
+### APP_ID申请
+
+可登录[个推官网](https://dev.getui.com/)注册申请应用,获取APP相关信息。
+
+
+
+### 多厂商
+
+多厂商渠道可以参考[[厂商应用开通指南-个推文档中心](https://docs.getui.com/getui/mobile/vendor/vendor_open/) 和 [厂商 SDK 集成指南-个推文档中心](https://docs.getui.com/getui/mobile/vendor/androidstudio/)
+
+> 注意:华为厂商需要把`agconnect-services.json` 放到${工程根目录}/nativeResources/android/ 目录下
+
+### 开发文档
+
+[个推推送SDK](https://docs.getui.com/getui/start/accessGuide/)
+[多厂商接入](https://docs.getui.com/getui/mobile/vendor/vendor_open/)
+
+
+
+### 注意事项
+
+在`AndroidManifest.xml`中,必须声明插件`flag`
+
+```xml
+
+
+```
diff --git a/uni_modules/uni-push/utssdk/app-android/AndroidManifest.xml b/uni_modules/uni-push/utssdk/app-android/AndroidManifest.xml
new file mode 100644
index 0000000000000000000000000000000000000000..0272d5637496aceebc0a71a2908eb3d5eb81cfaf
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/AndroidManifest.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/config.json b/uni_modules/uni-push/utssdk/app-android/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..82b9613f2c85c6060d2af8bb064882b2b5003711
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/config.json
@@ -0,0 +1,42 @@
+{
+ "parameters": {
+ "appid": {
+ "placeholder": "GETUI_APPID"
+ },
+ "mipush_appid": {
+ "placeholder": "MIPUSH_APPID"
+ },
+ "mipush_appkey": {
+ "placeholder": "MIPUSH_APPKEY"
+ },
+ "meizupush_appid": {
+ "placeholder": "MEIZUPUSH_APPID"
+ },
+ "meizupush_appkey": {
+ "placeholder": "MEIZUPUSH_APPKEY"
+ },
+ "oppopush_appkey": {
+ "placeholder": "OPPOPUSH_APPKEY"
+ },
+ "oppopush_appsecret": {
+ "placeholder": "OPPOPUSH_APPSECRET"
+ },
+ "huaweipush_appid": {
+ "placeholder": "com.huawei.hms.client.appid"
+ },
+ "vivopush_appid": {
+ "placeholder": "com.vivo.push.app_id"
+ },
+ "vivopush_appkey": {
+ "placeholder": "com.vivo.push.api_key"
+ },
+ "dcloud_unipush_auto_notification": {
+ "placeholder": "dcloud_unipush_auto_notification"
+ }
+ },
+ "files": [{
+ "source": "push_unipush_huaweipush_agconnect-services.json",
+ "target": "agconnect-services.json",
+ "des": "HMS配置文件"
+ }]
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/gt-sdk/GTPush.uts b/uni_modules/uni-push/utssdk/app-android/gt-sdk/GTPush.uts
new file mode 100644
index 0000000000000000000000000000000000000000..0ebb25a3c9b0bf9ddb234557ce6e4f506ff2db3c
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/gt-sdk/GTPush.uts
@@ -0,0 +1,144 @@
+import Context from "android.content.Context";
+import GTPlugin from "com.getui.sdk.GTPlugin";
+import IPushAction from "com.getui.sdk.IPushAction";
+import GTCmdMessage from "com.igexin.sdk.message.GTCmdMessage";
+import GTNotificationMessage from "com.igexin.sdk.message.GTNotificationMessage";
+import GTTransmitMessage from "com.igexin.sdk.message.GTTransmitMessage";
+import IUserLoggerInterface from "com.igexin.sdk.IUserLoggerInterface";
+
+export function gtInit(context : Context) : void {
+ GTPlugin.initialize(context);
+}
+
+export function getClientId(context : Context) : string {
+ return GTPlugin.getClientId(context);
+}
+
+export function setPushAction(action : UserPushAction) : void {
+ GTPlugin.setPushAction(action);
+}
+
+
+export type GTPushActionOptions = {
+
+ onReceiveServicePid ?: (res : number) => void
+
+ /**
+ * 接收clientId(cid)
+ */
+ onReceiveClientId ?: (res : string) => void
+
+ /**
+ * 此方法用于接收和处理透传消息。透传消息个推只传递数据,不做任何处理,客户端接收到透传消息后需要自己去做后续动作处理,如通知栏展示、弹框等。
+ * 如果开发者在客户端将透传消息创建了通知栏展示,建议将展示和点击回执上报给个推。
+ */
+ onReceiveMessageData ?: (res : string) => void
+
+ /**
+ * cid 离线上线通知
+ */
+ onReceiveOnlineState ?: (res : boolean) => void
+
+ /**
+ * 各种事件处理回执
+ */
+ onReceiveCommandResult ?: (res : GTCmdMessage) => void
+
+ /**
+ * 通知点击,只有个推通道下发的通知会回调此方法
+ */
+ onNotificationMessageClicked ?: (res : string) => void
+
+ /**
+ * 通知到达,只有个推通道下发的通知会回调此方法
+ */
+ onNotificationMessageArrived ?: (res : GTNotificationMessage) => void
+}
+
+
+
+export class UserPushAction implements IPushAction {
+
+ constructor(
+ private options : GTPushActionOptions) {
+ }
+
+ override onReceiveServicePid(ctx : Context, pid : Int) {
+ this.options.onReceiveServicePid?.(pid)
+ }
+
+ /**
+ * 接收clientId(cid)
+ */
+ override onReceiveClientId(ctx : Context, cid : string) {
+ this.options.onReceiveClientId?.(cid)
+ }
+
+ /**
+ * 此方法用于接收和处理透传消息。透传消息个推只传递数据,不做任何处理,客户端接收到透传消息后需要自己去做后续动作处理,如通知栏展示、弹框等。
+ * 如果开发者在客户端将透传消息创建了通知栏展示,建议将展示和点击回执上报给个推。
+ *
+ * class GTTransmitMessage {
+ * private String taskId;
+ * private String messageId;
+ * private String payloadId;
+ * private byte[] payload;
+ * }
+ */
+ override onReceiveMessageData(ctx : Context, message : GTTransmitMessage) {
+ this.options.onReceiveMessageData?.(new String(message.getPayload()))
+ }
+
+ /**
+ * cid 离线/上线通知
+ */
+ override onReceiveOnlineState(ctx : Context, state : boolean) {
+ this.options.onReceiveOnlineState?.(state)
+ }
+
+ /**
+ * 各种事件处理回执
+ */
+ override onReceiveCommandResult(ctx : Context, message : GTCmdMessage) {
+ this.options.onReceiveCommandResult?.(message)
+ }
+
+ /**
+ * 通知点击,只有个推通道下发的通知会回调此方法
+ */
+ override onNotificationMessageClicked(ctx : Context, message : GTNotificationMessage) {
+ const params = {
+ "title": message.getTitle(),
+ "content": message.getContent()
+ };
+ this.options.onNotificationMessageClicked?.(JSON.stringify(params))
+ }
+
+ /**
+ * 通知到达,只有个推通道下发的通知会回调此方法
+ */
+ override onNotificationMessageArrived(ctx : Context, message : GTNotificationMessage) {
+ this.options.onNotificationMessageArrived?.(message)
+ }
+}
+
+
+class UserLoggerInterface implements IUserLoggerInterface {
+ constructor(private callback : (log : string) => void) {
+ }
+
+ override log(s : string) {
+ this.callback?.(s)
+ }
+}
+
+/**
+ * 个推推送sdk调试日志信息
+ * setDebugLogger 接口仅限调试的时候使用,切勿发布到线上版本,重复调用仅以第一次为准。
+ */
+export function setDebugLogger(callback : (log : string) => void) {
+ const ctx = UTSAndroid.getAppContext();
+ if (ctx != null) {
+ GTPlugin.setDebugLogger(ctx, new UserLoggerInterface(callback))
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/index.uts b/uni_modules/uni-push/utssdk/app-android/index.uts
new file mode 100644
index 0000000000000000000000000000000000000000..34379f2b9c0c8aaba15f09e095b767966c947f8c
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/index.uts
@@ -0,0 +1,364 @@
+
+import { GetPushClientIdOptions, GetPushClientIdSuccess, GetPushClientIdFail, OnPushMessageCallback, OnPushMessageCallbackResult, OnPushMessageType, CreatePushMessageOptions, ChannelManager } from '../interface.uts'
+
+import { gtInit, GTPushActionOptions, UserPushAction, setPushAction } from './gt-sdk/GTPush.uts'
+import Context from 'android.content.Context';
+import { PushMessage } from './push/PushMessage.uts';
+import PackageManager from 'android.content.pm.PackageManager';
+import ApplicationInfo from 'android.content.pm.ApplicationInfo';
+import Activity from 'android.app.Activity';
+import TextUtils from 'android.text.TextUtils';
+import { PushState } from './push/PushState.uts';
+import { PushManager } from './push/PushManager.uts';
+import { StringUtil } from './push/utils/StringUtil.uts';
+import SharedPreferences from 'android.content.SharedPreferences';
+import Handler from 'android.os.Handler';
+import { PushChannelManager } from './push/PushChannelManager.uts';
+import Bundle from 'android.os.Bundle';
+import Intent from 'android.content.Intent';
+import Uri from 'android.net.Uri';
+import { globalPushMessageCallbacks, sendEvent } from './push/PushManager.uts'
+export { PushActionService } from './push/PushActionService.uts';
+
+const SP_NAME = "clientid_unipush";
+const SP_KEY_CLIENT_ID = "clientid";
+
+
+let gtCallBack : UserPushAction | null = null;
+let gtPushInitialize = false
+
+/**
+ * 个推推送sdk初始化
+ */
+function initPush() {
+ const ctx = UTSAndroid.getAppContext();
+ if (ctx != null && !gtPushInitialize) {
+ gtPushInitialize = true;
+ gtInit(ctx);
+ setPushAction(getGTCallBack());
+ }
+}
+
+/**
+ * 获取客户端唯一的推送标识(注意:这是一个异步的方法)
+ */
+export function getPushClientId(options : GetPushClientIdOptions) {
+ initPush()
+ const ctx = UTSAndroid.getAppContext() as Context;
+ const sp = ctx.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE) as SharedPreferences;
+ const clientId = sp.getString(SP_KEY_CLIENT_ID, "")
+ if (TextUtils.isEmpty(clientId)) {
+ const handler = new Handler()
+ const changeListener = new (class implements SharedPreferences.OnSharedPreferenceChangeListener {
+ override onSharedPreferenceChanged(sharedPreferences : SharedPreferences, key : string) : void {
+ if (key != SP_KEY_CLIENT_ID) {
+ return
+ }
+ handler.removeCallbacksAndMessages(null)
+ sharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
+ const cid = sharedPreferences.getString(SP_KEY_CLIENT_ID, "")
+ const res : GetPushClientIdSuccess = { errMsg: "success", cid: cid!! }
+ options.success?.(res)
+ options.complete?.(res)
+ }
+ })
+ sp.registerOnSharedPreferenceChangeListener(changeListener)
+
+ const runnable = new (class implements Runnable {
+ override run() {
+ const clientId = sp.getString(SP_KEY_CLIENT_ID, "")
+ if (!TextUtils.isEmpty(clientId)) {
+ const res : GetPushClientIdSuccess = { errMsg: "success", cid: clientId!! }
+ options.success?.(res)
+ options.complete?.(res)
+ } else {
+ const res : GetPushClientIdFail = {
+ errSubject: "uni-push",
+ errCode: -1,
+ errMsg: "failed,check appkey or appid",
+ }
+ options.fail?.(res)
+ options.complete?.(res)
+ }
+ }
+ })
+ handler.postDelayed(runnable, 15000)
+ } else {
+ const res : GetPushClientIdSuccess = { errMsg: "success", cid: clientId!! }
+ options.success?.(res)
+ options.complete?.(res)
+ }
+}
+
+/**
+ * 增加监听推送消息事件(应用在线的时候没有通知栏消息,全部是透传。), 注意: 使用时,开发者需要注册写到第一个activity的周期内 , 即首页.
+ */
+export function onPushMessage(callback : OnPushMessageCallback | null) {
+ initPush()
+ if (callback == null) {
+ return;
+ }
+ if (globalPushMessageCallbacks.indexOf(callback) == -1) {
+ globalPushMessageCallbacks.push(callback)
+ }
+
+ processOfflineMessage()
+ // 处理没有注册监听时,已经接到的消息,此时从缓存里取
+ PushManager.getInstance().comsumeMessages("click", (msgs : PushMessage[]) => {
+ msgs.forEach((msg) => {
+ sendEvent("click", msg)
+ })
+ })
+ PushManager.getInstance().comsumeMessages("receive", (msgs : PushMessage[]) => {
+ msgs.forEach((msg) => {
+ sendEvent("receive", msg)
+ })
+ })
+}
+
+/**
+ * 移除推送消息监听事件(没有传入参数,则移除App级别的所有事件监听器。)
+ */
+export function offPushMessage(callback : OnPushMessageCallback | null) {
+ if (callback == null) {
+ const len = globalPushMessageCallbacks.length;
+ globalPushMessageCallbacks.splice(0, len)
+ return;
+ }
+
+ let index = globalPushMessageCallbacks.indexOf(callback)
+ if (index == -1) {
+ return;
+ }
+ globalPushMessageCallbacks.splice(index, 1)
+}
+
+export function getChannelManager() : ChannelManager {
+ return PushChannelManager.getInstance()
+}
+
+export function createPushMessage(options : CreatePushMessageOptions) : void {
+ const context = UTSAndroid.getAppContext() as Context
+ const appId = UTSAndroid.getAppId()
+ const pushMessage = new PushMessage(JSON.stringify(options), getApplicationName(), false)
+
+ const min = 0
+ if (pushMessage.mDelay == min.toLong()) {
+ PushManager.getInstance().addPushMessage(appId, pushMessage)
+ PushManager.getInstance().createNotification(context, pushMessage)
+ } else {
+ new Handler().postDelayed(new (class implements Runnable {
+ override run() {
+ PushManager.getInstance().addPushMessage(appId, pushMessage)
+ PushManager.getInstance().createNotification(context, pushMessage)
+ }
+ }), pushMessage.mDelay * 1000)
+ }
+}
+
+
+function getGTCallBack() : UserPushAction {
+ if (gtCallBack == null) {
+ const options = {
+ onReceiveClientId(cid : string) {
+ const context = UTSAndroid.getAppContext() as Context;
+ const sp = context.getSharedPreferences(SP_NAME, Context.MODE_PRIVATE);
+ const editor = sp.edit();
+ editor.putString(SP_KEY_CLIENT_ID, cid);
+ editor.commit();
+ },
+ onNotificationMessageClicked(res : string) {
+ const pushMessage = new PushMessage(res, getApplicationName(), false)
+ if (!sendEvent("click", pushMessage)) {
+ PushManager.getInstance().addNeedExecClickMessage(pushMessage)
+ }
+ },
+ onReceiveMessageData(res : string) {
+ if (!TextUtils.isEmpty(res)) {
+ let isUniPush2 = false
+ const jsonObject = JSON.parseObject(res)
+ const unipushVersionStr = jsonObject?.getString("unipush_version")
+ if (!TextUtils.isEmpty(unipushVersionStr)) {
+ const unipushVersion = parseFloat(unipushVersionStr!!)
+ if (unipushVersion == 2.0) {
+ isUniPush2 = true;
+ }
+ }
+ if (isUniPush2) {
+ processForUniPush2(res);
+ } else {
+ processForUniPush(res);
+ }
+ }
+ },
+ } as GTPushActionOptions;
+ gtCallBack = new UserPushAction(options);
+ }
+
+ return gtCallBack!!;
+}
+
+/**
+ * 处理离线消息
+ */
+function processOfflineMessage() {
+ const activity = UTSAndroid.getUniActivity() as Activity
+ const intent = activity.getIntent()
+
+ // const testStr = "intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;package=uni.UNI8CD4C4C;component=uni.UNI8CD4C4C/io.dcloud.uniapp.UniAppActivity;S.UP-OL-SU=true;S.unipush_version=2.0;S.payload={\"cccccforceNotification\":\"xxx\",\"path\":\"XXX\"};S.title=xxx;S.content=xxx;S.unipush_data={\"forceNotification\":\"xxx\",\"path\":\"XXX\"};end"
+ // const intent = Intent.parseUri(testStr , 0)
+
+ if (intent.hasExtra("UP-OL-SU")) {
+ let isUniPush2 = false;
+ const unipushVersionStr = intent.getStringExtra("unipush_version");
+ if (!TextUtils.isEmpty(unipushVersionStr)) {
+ const unipushVersion = parseFloat(unipushVersionStr!!)
+ if (unipushVersion == 2.0) {
+ isUniPush2 = true;
+ }
+ }
+
+ const params = {}
+
+ if (isUniPush2) {
+ try {
+ params["title"] = intent.getStringExtra("title")
+ params["content"] = intent.getStringExtra("content")
+ params["unipush_version"] = intent.getStringExtra("unipush_version")
+
+ const channelId = intent.getStringExtra("channelId");
+ const category = intent.getStringExtra("category");
+ if (!TextUtils.isEmpty(channelId)) {
+ params["channelId"] = channelId
+ }
+ if (!TextUtils.isEmpty(category)) {
+ params["category"] = category
+ }
+
+ let payload = intent.getStringExtra("payload");
+ const payloadJsonObject = JSON.parseObject(payload ?? "")
+ if (payloadJsonObject == null) {
+ if (payload != null) {
+ //如果后端传的不是json,而是纯字符串,就需要单独处理,去掉多余的引号,并且枚举一下类型.
+ //双引号套双引号,就说明是传的字符串.
+ if (payload.startsWith("\"")) {
+ payload = StringUtil.trimString(payload, '"');
+ params["payload"] = payload
+ } else {
+ const payloadInt = StringUtil.getInt(payload);
+ const payloadDouble = StringUtil.getDouble(payload);
+ if (payloadInt != null) {
+ params["payload"] = payloadInt
+ } else if (payloadDouble != null) {
+ params["payload"] = payloadDouble
+ } else if (payload == "true" || payload == "false") {
+ params["payload"] = payload.toBoolean()
+ } else {
+ params["payload"] = payload
+ }
+ }
+ }
+ } else {
+ params["payload"] = payloadJsonObject
+ }
+
+ const unipush_data = intent.getStringExtra("unipush_data");
+ const unipushDataJsonObject = JSON.parseObject(unipush_data ?? "");
+ if (unipushDataJsonObject != null) {
+ unipushDataJsonObject.toMap().forEach((value, key) => {
+ params[key] = value
+ })
+ }
+
+ intent.removeExtra("UP-OL-SU");
+ intent.removeExtra("title");
+ intent.removeExtra("content");
+ intent.removeExtra("payload");
+ intent.removeExtra("unipush_version");
+ intent.removeExtra("unipush_data");
+ intent.removeExtra("channelId");
+ intent.removeExtra("category");
+
+ const data = JSON.stringify(params)
+ const pushMessage = new PushMessage(data, getApplicationName(), true);
+ if (!sendEvent("click", pushMessage)) {
+ PushManager.getInstance().addNeedExecClickMessage(pushMessage)
+ }
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ } else {
+ try {
+ params["title"] = intent.getStringExtra("title")
+ params["content"] = intent.getStringExtra("content")
+ params["payload"] = intent.getStringExtra("payload")
+ const channelId = intent.getStringExtra("channelId");
+ const category = intent.getStringExtra("category");
+ if (!TextUtils.isEmpty(channelId)) {
+ params["channelId"] = channelId
+ }
+ if (!TextUtils.isEmpty(category)) {
+ params["category"] = category
+ }
+ intent.removeExtra("UP-OL-SU");
+ intent.removeExtra("title");
+ intent.removeExtra("content");
+ intent.removeExtra("payload");
+ intent.removeExtra("channelId");
+ intent.removeExtra("category");
+ const data = JSON.stringify(params)
+ const pushMessage = new PushMessage(data, getApplicationName(), true);
+ if (!sendEvent("click", pushMessage)) {
+ PushManager.getInstance().addNeedExecClickMessage(pushMessage)
+ }
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ }
+ }
+}
+
+
+function processForUniPush(data : string) : void {
+ const context = UTSAndroid.getAppContext() as Context
+ const pushMessage = new PushMessage(data, getApplicationName(), false)
+ const needPush = PushState.getAutoNotification()
+ if (needPush && pushMessage.getNeedCreateNotification()) {
+ PushManager.getInstance().createNotification(context, pushMessage)
+ } else if (!sendEvent("receive", pushMessage)) {
+ PushManager.getInstance().addNeedExecReceiveMessage(pushMessage);
+
+ }
+ PushManager.getInstance().addPushMessage(UTSAndroid.getAppId(), pushMessage);
+}
+
+function processForUniPush2(data : string) : void {
+ const context = UTSAndroid.getAppContext() as Context
+ const jsonObject = JSON.parseObject(data)
+ if (jsonObject != null) {
+ const forceNotification = jsonObject.getBoolean("force_notification")
+ const pushMessage = new PushMessage(data, getApplicationName(), true)
+ if (forceNotification != null && forceNotification) {
+ PushManager.getInstance().createNotification(context, pushMessage)
+ } else if (!sendEvent("receive", pushMessage)) {
+ PushManager.getInstance().addNeedExecReceiveMessage(pushMessage);
+ }
+ PushManager.getInstance().addPushMessage(UTSAndroid.getAppId(), pushMessage);
+ }
+}
+
+function getApplicationName() : string {
+ let packageManager : PackageManager | null = null
+ let applicationInfo : ApplicationInfo | null = null
+ const context = UTSAndroid.getAppContext() as Context;
+ try {
+ packageManager = context.getApplicationContext().getPackageManager()
+ applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0)
+ } catch (_ : Exception) {
+ }
+ if (applicationInfo == null) {
+ return ""
+ }
+
+ return packageManager?.getApplicationLabel(applicationInfo).toString() ?? ""
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/libs/getui-uts-android-release-20230928135005.aar b/uni_modules/uni-push/utssdk/app-android/libs/getui-uts-android-release-20230928135005.aar
new file mode 100644
index 0000000000000000000000000000000000000000..93354738c7fef06d3cd9a7d1d48aecd68204616a
Binary files /dev/null and b/uni_modules/uni-push/utssdk/app-android/libs/getui-uts-android-release-20230928135005.aar differ
diff --git a/uni_modules/uni-push/utssdk/app-android/push/PushActionService.uts b/uni_modules/uni-push/utssdk/app-android/push/PushActionService.uts
new file mode 100644
index 0000000000000000000000000000000000000000..886709c8f29ca335d70fff3c7ad886df655d2790
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/PushActionService.uts
@@ -0,0 +1,21 @@
+import Service from 'android.app.Service';
+import Intent from 'android.content.Intent';
+import IBinder from 'android.os.IBinder';
+import { PushManager } from './PushManager.uts';
+export class PushActionService extends Service {
+
+ constructor(){
+ super();
+ }
+
+ override onBind(intent : Intent) : IBinder | null {
+ return null
+ }
+
+ override onStartCommand(intent : Intent | null, flag : Int, startId : Int) : Int {
+ if (intent != null) {
+ PushManager.getInstance().processAction(this.getBaseContext(), intent)
+ }
+ return super.onStartCommand(intent, flag, startId)
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/push/PushChannelManager.uts b/uni_modules/uni-push/utssdk/app-android/push/PushChannelManager.uts
new file mode 100644
index 0000000000000000000000000000000000000000..07f55431709507f1a2b50c6d6ffe946b8266bf3c
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/PushChannelManager.uts
@@ -0,0 +1,98 @@
+import { ChannelManager, SetPushChannelOptions } from "../../interface.uts";
+import Context from 'android.content.Context';
+import Build from 'android.os.Build';
+import NotificationManager from 'android.app.NotificationManager';
+import NotificationChannelGroup from 'android.app.NotificationChannelGroup';
+import NotificationChannel from 'android.app.NotificationChannel';
+import TextUtils from 'android.text.TextUtils';
+import ContentResolver from 'android.content.ContentResolver';
+import Uri from 'android.net.Uri';
+import RingtoneManager from 'android.media.RingtoneManager';
+
+export class PushChannelManager implements ChannelManager {
+
+ static LOCAL_PUSH_CHANNEL_ID = "DcloudChannelID";
+ static LOCAL_PUSH_GROUP_ID = "DcloudGroupID";
+
+ private static INSTANCE : PushChannelManager | null = null
+
+ static getInstance() : PushChannelManager {
+ if (this.INSTANCE == null) {
+ this.INSTANCE = new PushChannelManager()
+ }
+ return this.INSTANCE!!
+ }
+
+ createDefaultChannel(context : Context) {
+ if (Build.VERSION.SDK_INT >= 26) {
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ const pChannelId = PushChannelManager.LOCAL_PUSH_CHANNEL_ID
+ const pChannelName = context.getResources().getString(R.string.dcloud_feature_aps_notification_channel)
+ if (notificationManager.getNotificationChannel(pChannelId) == null) {
+ notificationManager.createNotificationChannelGroup(new NotificationChannelGroup(PushChannelManager.LOCAL_PUSH_GROUP_ID, context.getResources().getString(R.string.dcloud_feature_aps_notification_group)))
+ const channel = new NotificationChannel(pChannelId, pChannelName, NotificationManager.IMPORTANCE_DEFAULT)
+ channel.enableLights(true)
+ channel.setShowBadge(true)
+ notificationManager.createNotificationChannel(channel)
+ }
+ }
+ }
+
+ /**
+ * 设置推送渠道
+ */
+ setPushChannel(options : SetPushChannelOptions) : void {
+ if (Build.VERSION.SDK_INT >= 26) {
+ const context = UTSAndroid.getAppContext() as Context
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager;
+ if (notificationManager.getNotificationChannel(options.channelId) == null) {
+ const notificationChannel = new NotificationChannel(options.channelId, options.channelDesc, NotificationManager.IMPORTANCE_DEFAULT);
+ notificationChannel.setShowBadge(true);
+ let sound = 0;
+ if (!TextUtils.isEmpty(options.soundName)) {
+ const packName = context.getApplicationInfo().packageName
+ sound = context.getResources().getIdentifier(options.soundName!!, "raw", packName)
+ }
+ let uriStr = "";
+ if (sound != 0) {
+ uriStr = ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + context.getPackageName() + "/raw/" + sound;
+ }
+
+ if (!TextUtils.isEmpty(uriStr)) {
+ notificationChannel.setSound(Uri.parse(uriStr), null);
+ } else {
+ const uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);//默认铃音
+ notificationChannel.setSound(uri, null);
+ }
+
+ if (options.importance != null) {
+ notificationChannel.setImportance(options.importance!!.toInt());
+ }
+ if (options.lockscreenVisibility != null) {
+ notificationChannel.setLockscreenVisibility(options.lockscreenVisibility!!.toInt());
+ }
+ notificationChannel.enableLights(options.enableLights ?? false);
+ notificationChannel.enableVibration(options.enableVibration ?? false);
+ notificationManager.createNotificationChannel(notificationChannel);
+ }
+ }
+ }
+ /**
+ * 获取当前应用注册的所有的通知渠道。
+ */
+ getAllChannels() : string[] {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ const context = UTSAndroid.getAppContext() as Context
+ const nm = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ const channels : string[] = []
+ const list = nm.getNotificationChannels()
+ for (let i:Int = 0; i < list.size; i++) {
+ channels.push(list.get(i).toString())
+ }
+ return channels
+ }else{
+ return [] as string[]
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/push/PushManager.uts b/uni_modules/uni-push/utssdk/app-android/push/PushManager.uts
new file mode 100644
index 0000000000000000000000000000000000000000..bbc8b88effc02986f81d65de0df74742033baff3
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/PushManager.uts
@@ -0,0 +1,320 @@
+import Context from 'android.content.Context';
+import Intent from 'android.content.Intent';
+import { PushChannelManager } from './PushChannelManager.uts';
+import { PushMessage } from './PushMessage.uts';
+import NotificationManager from 'android.app.NotificationManager';
+import ComponentName from 'android.content.ComponentName';
+import PendingIntent from 'android.app.PendingIntent';
+import Build from 'android.os.Build';
+import TextUtils from 'android.text.TextUtils';
+import Notification from 'android.app.Notification';
+import Bitmap from 'android.graphics.Bitmap';
+import BitmapFactory from 'android.graphics.BitmapFactory';
+import File from 'java.io.File';
+import { OnPushMessageCallback, OnPushMessageType, OnPushMessageCallbackResult } from '../../interface.uts'
+
+export const globalPushMessageCallbacks : OnPushMessageCallback[] = []
+
+export function sendEvent(type : OnPushMessageType, pushMessage : PushMessage) : boolean {
+ const data = pushMessage.getJsonObject()
+ const result : OnPushMessageCallbackResult = {
+ type: type,
+ data: data
+ }
+ if (globalPushMessageCallbacks.length == 0) {
+ return false
+ } else {
+ globalPushMessageCallbacks.forEach((cb : OnPushMessageCallback) => {
+ cb(result)
+ })
+ return true
+ }
+}
+
+export class PushManager {
+ private static INSTANCE : PushManager | null = null
+
+ private ACTION_TYPE_CREATE = "ACTION_TYPE_CREATE"
+ private ACTION_TYPE_REMOVE = "ACTION_TYPE_REMOVE"
+ private ACTION_TYPE_CLEAR = "ACTION_TYPE_CLEAR"
+ private ACTION_TYPE_CLICK = "ACTION_TYPE_CLICK"
+
+ private mAppMessages : Map> = new Map()
+ private mNeedExecClickMessages : PushMessage[] = []
+ private mNeedExecReceiveMessages : PushMessage[] = []
+
+ static getInstance() : PushManager {
+ if (this.INSTANCE == null) {
+ this.INSTANCE = new PushManager()
+ }
+ return this.INSTANCE!!
+ }
+
+
+
+
+
+ createNotification(context : Context, message : PushMessage) {
+ PushChannelManager.getInstance().createDefaultChannel(context)
+ const intent = new Intent(this.ACTION_TYPE_CREATE)
+ intent.putExtras(message.toBundle())
+ this.processAction(context, intent)
+ }
+
+ addPushMessage(pAppid : string, pMsg : PushMessage) {
+ let _arr = this.mAppMessages.get(pAppid);
+ if (_arr == null) {
+ _arr = new Array();
+ this.mAppMessages.set(pAppid, _arr);
+ }
+ _arr.push(pMsg);
+ }
+
+
+ addNeedExecClickMessage(pushMessage : PushMessage) {
+ if (this.mNeedExecClickMessages.length > 0) {
+ this.mNeedExecClickMessages = []
+ }
+ this.mNeedExecClickMessages.push(pushMessage)
+ }
+
+ addNeedExecReceiveMessage(pushMessage : PushMessage) {
+ this.mNeedExecReceiveMessages.push(pushMessage)
+ }
+
+ removePushMessage(pAppid : String, pPushMsg : PushMessage) {
+ const _arr = this.mAppMessages.get(pAppid);
+ if (_arr != null && _arr.indexOf(pPushMsg) > 0) {
+ _arr.splice(_arr.indexOf(pPushMsg), 1);
+ }
+ }
+
+ /**
+ * 消费缓存的消息
+ */
+ comsumeMessages(type : string, cb : (msgs : PushMessage[]) => void) {
+ if (type == "click") {
+ cb(this.mNeedExecClickMessages)
+ this.mNeedExecClickMessages.splice(0)
+ } else if (type == "receive") {
+ cb(this.mNeedExecReceiveMessages)
+ this.mNeedExecReceiveMessages.splice(0)
+ }
+ }
+
+
+ processAction(context : Context, intent : Intent) {
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ const action = intent.getAction()
+ switch (action) {
+ case this.ACTION_TYPE_CREATE:
+ {
+ const title = intent.getStringExtra("title");
+ const message = intent.getStringExtra("content");
+ const nId = intent.getIntExtra("nId", 0);
+ const when = intent.getLongExtra("when", 0);
+ const appid = intent.getStringExtra("appid");
+ const icon = intent.getStringExtra("icon");
+ const sound = intent.getStringExtra("sound");
+ const category = intent.getStringExtra("category");
+ let channelId = intent.getStringExtra("channelId");
+ const i = new Intent(this.ACTION_TYPE_CLICK);
+ i.setComponent(new ComponentName(context.getPackageName(), "uts.sdk.modules.DCloudUniPush.PushActionService"));
+ i.putExtras(intent.getExtras()!!);
+ let flags = PendingIntent.FLAG_ONE_SHOT;
+ if (Build.VERSION.SDK_INT >= 23) {
+ flags = PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE;
+ }
+ const contentIntent = PendingIntent.getService(context, nId, i, flags);
+
+ let builder : Notification.Builder | null = null;
+ if (Build.VERSION.SDK_INT >= 26) {
+ if (TextUtils.isEmpty(channelId)) {
+ channelId = PushChannelManager.LOCAL_PUSH_CHANNEL_ID;
+ }
+ builder = new Notification.Builder(context, channelId);
+ } else {
+ builder = new Notification.Builder(context);
+ }
+
+ let bitmap : Bitmap | null = null;
+ try {
+ if (!TextUtils.isEmpty(icon) && this.fileIsExist(icon!!)) {
+ bitmap = BitmapFactory.decodeFile(icon!!);
+ }
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ if (bitmap != null) {
+ builder.setLargeIcon(bitmap);
+ }
+
+ const id_small = context.getResources().getIdentifier("push_small", "drawable", context.getPackageName())
+ if (id_small <= 0) {
+ builder.setSmallIcon(context.getApplicationInfo().icon); //设置图标
+ } else {
+ builder.setSmallIcon(id_small); //设置图标
+ }
+
+ const id = context.getResources().getIdentifier("push", "drawable", context.getPackageName())
+ if (bitmap == null) {
+ let largeBitmap : Bitmap | null = null;
+ if (id <= 0) {
+ largeBitmap = BitmapFactory.decodeResource(context.getResources(), context.getApplicationInfo().icon);
+ } else {
+ largeBitmap = BitmapFactory.decodeResource(context.getResources(), id);
+ }
+ if (null != largeBitmap) {
+ builder.setLargeIcon(largeBitmap);
+ }
+ }
+ builder.setContentTitle(title); //设置标题
+ builder.setContentText(message); //消息内容
+ if (Build.VERSION.SDK_INT >= 24) {
+ builder.setShowWhen(true);
+ }
+ builder.setWhen(when); //发送时间
+
+ // 添加声音提示
+ if ("system" == sound) {
+ builder.setDefaults(Notification.DEFAULT_SOUND); //设置默认的提示音,振动方式,灯光
+ }
+ builder.setAutoCancel(true);//打开程序后图标消失
+ builder.setContentIntent(contentIntent);
+ builder.setCategory(category);
+ const notification = builder.build();
+ try {
+ notificationManager.notify(nId, notification);
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ }
+
+ break;
+ case this.ACTION_TYPE_REMOVE:
+ {
+ const _id = intent.getIntExtra("id", 0);
+ if (_id != null) {
+ notificationManager.cancel(_id);
+ }
+ }
+ break;
+ case this.ACTION_TYPE_CLEAR:
+ {
+ notificationManager.cancelAll();
+ const _appid = intent.getStringExtra("_appId");
+ if (_appid != null) {
+ const appMsg = PushManager.getInstance().mAppMessages;
+ appMsg.delete(_appid);
+ }
+ }
+ break;
+ case this.ACTION_TYPE_CLICK:
+ {
+ this.clickHandle(intent, notificationManager);
+ const packagename = context.getPackageName();// 启动类所在包名
+ const pm = context.getPackageManager();
+ const _intent = pm.getLaunchIntentForPackage(packagename);
+ const appid = intent.getStringExtra("appid");
+ _intent?.putExtra("appid", appid);
+ const isStartWeb = intent?.getBooleanExtra("__start_first_web__", false) ?? false;
+ if (isStartWeb) {
+ _intent?.putExtra("__start_first_web__", isStartWeb);
+ _intent?.putExtra("__first_web_url__", intent?.getStringExtra("__first_web_url__"));
+ }
+ _intent?.putExtra("__start_from__", 3);
+ _intent?.putExtra("__payload__", intent?.getStringExtra("payload"));
+ _intent?.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
+ context.startActivity(_intent);
+ }
+ break;
+ }
+
+ }
+
+ clickHandle(intent : Intent, _notificationManager : NotificationManager) {
+ const _bundle = intent.getExtras()!!;
+ const appid = _bundle.getString("appid");
+ const uuid = _bundle.getString("uuid");
+ if (_notificationManager != null) {//作为插件时,手助负责创建通知栏消息
+ const _id = intent.getIntExtra("id", 0);
+ _notificationManager.cancel(_id);
+ }
+ let _pushMessage : PushMessage | null = null
+ if (appid != null && uuid != null) {
+ _pushMessage = this.findPushMessage(appid!!, uuid!!);
+ }
+ if (_pushMessage != null) {
+ let isStartWeb = false;
+ if (!TextUtils.isEmpty(_pushMessage.mPayload)) {
+ try {
+ const payLoadJson = JSON.parseObject(_pushMessage.mPayload ?? "")
+ const url = payLoadJson?.getString("__adurl")
+ if (!TextUtils.isEmpty(url)) {
+ intent.putExtra("__start_first_web__", true);
+ intent.putExtra("__first_web_url__", url);
+ isStartWeb = true;
+ }
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ }
+
+ if (!isStartWeb && !sendEvent("click", _pushMessage)) {
+ this.addNeedExecClickMessage(_pushMessage);
+ }
+ // 点击后的消息,需要移除消息记录,避免getAllMessage时不正确
+ if (appid != null) {
+ this.removePushMessage(appid, _pushMessage);
+ }
+ } else {
+ _pushMessage = new PushMessage(_bundle);
+ if (!TextUtils.isEmpty(_pushMessage.mPayload)) {
+ try {
+ const payLoadJson = JSON.parseObject(_pushMessage.mPayload!!)
+ const url = payLoadJson?.getString("__adurl")
+ if (!TextUtils.isEmpty(url)) {
+ intent.putExtra("__start_first_web__", true);
+ intent.putExtra("__first_web_url__", url);
+ }
+ } catch (e : Exception) {
+ e.printStackTrace();
+ }
+ }
+ this.addNeedExecClickMessage(_pushMessage);
+ }
+ _bundle.clear();
+ }
+
+
+
+ findPushMessage(pAppid : String, pUuid : String) : PushMessage | null {
+ let _ret : PushMessage | null = null;
+ const _arr = this.mAppMessages.get(pAppid);
+ if (_arr == null) {//若没有通过appid获取到消息集合,则通过uuid遍历所有消息
+ this.mAppMessages.forEach((value : PushMessage[], key : string) => {
+ if (value != null) {
+ value.forEach((value : PushMessage) => {
+ if (pUuid == value.getMessageUUID()) {
+ _ret = value
+ }
+ })
+ }
+ })
+ } else if (_arr != null) {
+ _arr.forEach((value : PushMessage) => {
+ if (pUuid == value.getMessageUUID()) {
+ _ret = value
+ }
+ })
+ }
+ return _ret;
+ }
+
+
+ fileIsExist(path : string) : boolean {
+ const realPath = UTSAndroid.convert2AbsFullPath(path)
+ const file = new File(realPath)
+ return file.exists()
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/push/PushMessage.uts b/uni_modules/uni-push/utssdk/app-android/push/PushMessage.uts
new file mode 100644
index 0000000000000000000000000000000000000000..ef84878939440a73a869e785081e1ea50f74b66c
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/PushMessage.uts
@@ -0,0 +1,275 @@
+import TextUtils from 'android.text.TextUtils'
+import Bundle from 'android.os.Bundle';
+
+export class PushMessage {
+ private mTitle : string | null = null
+ private contentJson : string | null = null
+ private mContent : string | null = null
+
+ mPayloadJSON : UTSJSONObject | null = null
+ mPayload : string | null = null
+
+ private mWhen : Long = 0
+ mDelay : Long = 0
+ private mPath : string | null = null
+ private mForceNotification : string | null = null
+ private channelId = ""
+ private category = ""
+ private mMessageAppid : string | null = null
+ private mIconPath : string | null = null
+
+ private mUUID : string | null = null
+ private nID : number = 0
+ private isCover = false
+ private sound = "system"
+ private static mNotificationId = 1
+ private needCreateNotification = true
+
+ private pushVersion : Float = 1.0.toFloat()
+ private extJSON : UTSJSONObject | null = null
+
+ constructor(data : string, defaultTitle : string, isUniPush2 : boolean) {
+ if (!isUniPush2) {
+ this.contentJson = data
+ this.parseJson(data, UTSAndroid.getAppId(), defaultTitle)
+ } else {
+ this.extJSON = JSON.parseObject(data)
+ this.mMessageAppid = UTSAndroid.getAppId()
+ this.pushVersion = 2.0.toFloat()
+ if (this.extJSON != null) {
+ this.channelId = this.extJSON!!.getString("channelId") ?? ""
+ this.category = this.extJSON!!.getString("category") ?? ""
+ }
+ }
+ this.setMessageUUID()
+ this.setNotificationID()
+ }
+
+ $constructor(b : Bundle) {
+ this.mTitle = b.getString("title");
+ this.mContent = b.getString("content");
+ this.nID = b.getInt("nId");
+ this.mWhen = b.getLong("when");
+ this.sound = b.getString("sound") ?? "system";
+ this.mMessageAppid = b.getString("appid");
+ this.mUUID = b.getString("uuid");
+ this.mPayload = b.getString("payload");
+ this.mIconPath = b.getString("icon");
+ this.channelId = b.getString("channelId", "");
+ this.category = b.getString("category", "");
+ }
+
+
+
+ getNeedCreateNotification() : boolean {
+ return this.needCreateNotification;//payload为空串时需要创建
+ }
+
+ getMessageUUID() : string | null {
+ return this.mUUID
+ }
+
+ getJsonObject() : UTSJSONObject {
+ if (this.extJSON != null) {
+ if (this.pushVersion == (2.0.toFloat())) {
+ try {
+ this.extJSON!!["__UUID__"] = this.mUUID
+ this.extJSON!!["appid"] = this.mMessageAppid
+ } catch (e : Exception) {
+ e.printStackTrace()
+ return {};
+ }
+ }
+ return this.extJSON!!
+ } else {
+ const result = {} as UTSJSONObject;
+ result["__UUID__"] = this.mUUID
+ result["title"] = this.mTitle
+ result["appid"] = this.mMessageAppid
+ result["content"] = this.mContent
+ if (this.mPayloadJSON != null) {
+ result["payload"] = this.cleanNullValue(this.mPayloadJSON!!)
+ } else {
+ let payLoadObj : UTSJSONObject | null = null
+ if (this.mPayload != null) {
+ payLoadObj = JSON.parseObject(this.mPayload!!)
+ }
+
+ if (payLoadObj != null) {
+ result["payload"] = this.cleanNullValue(payLoadObj)
+ } else {
+ result["payload"] = this.mPayload
+ }
+ }
+ if (!TextUtils.isEmpty(this.mPath)) {
+ result["path"] = this.mPath
+ }
+ if (!TextUtils.isEmpty(this.mForceNotification)) {
+ result["force_notification"] = this.mForceNotification
+ }
+ if (!TextUtils.isEmpty(this.channelId)) {
+ result["channelId"] = this.channelId
+ }
+ if (!TextUtils.isEmpty(this.category)) {
+ result["category"] = this.category
+ }
+ return result
+ }
+ }
+
+ cleanNullValue(json : UTSJSONObject) : UTSJSONObject {
+ const result = {}
+ json.toMap().forEach((value, key) => {
+ if (value != null) {
+ result[key] = value
+ }
+ })
+ return result
+ }
+
+
+ toBundle() : Bundle {
+ const bundle = new Bundle()
+ if (this.extJSON != null && this.pushVersion == (2.0.toFloat())) {
+ bundle.putInt("nId", this.nID.toInt());
+ bundle.putLong("when", this.mWhen);
+ bundle.putString("sound", this.sound);
+ bundle.putString("appid", this.mMessageAppid);
+ bundle.putString("uuid", this.mUUID);
+ bundle.putString("icon", this.mIconPath);
+
+ const map = this.extJSON!!.toMap()
+ map.forEach((value, key) => {
+ if (value != null) {
+ if (typeof value == 'string') {
+ bundle.putString(key, value as string);
+ } else if (value instanceof Integer) {
+ bundle.putInt(key, value as Int);
+ } else if (value instanceof Double) {
+ bundle.putDouble(key, value);
+ } else if (typeof value == 'boolean') {
+ bundle.putBoolean(key, value as boolean);
+ } else if (value instanceof UTSJSONObject) {
+ bundle.putString(key, (value as UTSJSONObject).toJSONString());
+ }
+ }
+ })
+ return bundle
+ }
+
+ bundle.putString("title", this.mTitle);
+ bundle.putString("content", this.mContent);
+ bundle.putInt("nId", this.nID.toInt());
+ bundle.putLong("when", this.mWhen);
+ bundle.putString("sound", this.sound);
+ bundle.putString("appid", this.mMessageAppid);
+ bundle.putString("uuid", this.mUUID);
+ if (this.mPayloadJSON != null) {
+ bundle.putString("payload", this.mPayloadJSON!!.toJSONString());
+ } else {
+ bundle.putString("payload", this.mPayload);
+ }
+ bundle.putString("icon", this.mIconPath);
+ bundle.putString("channelId", this.channelId);
+ bundle.putString("category", this.category);
+
+ return bundle
+ }
+
+
+
+ private setMessageUUID() : void {
+ this.mUUID = "androidPushMsg" + this.hashCode()
+ }
+
+ private setNotificationID() : void {
+ if (!this.isCover) {
+ PushMessage.mNotificationId++
+ }
+ this.nID = PushMessage.mNotificationId
+ }
+
+
+ /**
+ * 解析消息的数据
+ * @param defaultAppid 通过appid 查询到icon资源 , 1.0强需求, 2.0 不需求
+ */
+ private parseJson(data : string, defaultAppid : string, defaultTitle : string) : void {
+ const json = JSON.parseObject(data)
+ if (json != null) {
+ let t_appid = json.getString("appid")
+ const content = json.getString("content")
+ if (content != null) {
+ this.mContent = content
+ } else {
+ const message = json.getString("message")
+ if (message != null) {
+ this.mContent = message
+ } else {
+ this.needCreateNotification = true
+ this.mContent = data
+ }
+ }
+
+ if (this.hasOwnProperty(json, "payload")) {
+ const payloadJson = json.getJSON("payload")
+ if (payloadJson != null) {
+ this.mPayloadJSON = payloadJson
+ } else {
+ this.mPayload = json.getString("payload")
+ }
+ } else {
+ if (this.hasOwnProperty(json, "Payload")) {
+ const payloadJson = json.getJSON("Payload")
+ if (payloadJson != null) {
+ this.mPayloadJSON = payloadJson
+ } else {
+ this.mPayload = json.getString("Payload")
+ }
+ } else {
+ this.needCreateNotification = false
+ this.mPayload = data
+ }
+ }
+
+ if (this.hasOwnProperty(json, "title")) {
+ this.mTitle = json.getString("title")
+ } else {
+ this.needCreateNotification = false
+ this.mTitle = defaultTitle
+ }
+
+ this.isCover = json.getBoolean("cover") ?? false
+ if ("none" == json.getString("sound")) {
+ this.sound = "none"
+ }
+ this.mWhen = (json.getNumber("when") ?? 0).toLong()
+ this.mDelay = (json.getNumber("delay") ?? 0).toLong()
+
+ this.mPath = json.getString("path")
+ this.mForceNotification = json.getString("force_notification")
+ this.channelId = json.getString("channelId") ?? ""
+ this.category = json.getString("category") ?? ""
+
+ if (TextUtils.isEmpty(t_appid)) {
+ t_appid = defaultAppid
+ }
+ this.mMessageAppid = t_appid
+ const iconPath = json.getString("icon") ?? ""
+ this.mIconPath = UTSAndroid.convert2AbsFullPath(iconPath)
+ } else {
+ this.needCreateNotification = false
+ this.mContent = data
+ this.mPayload = data
+ this.mTitle = defaultTitle
+ }
+ }
+
+
+ private hasOwnProperty(jsonObject : UTSJSONObject, key : string) : boolean {
+ return jsonObject.getAny(key) != null
+ }
+
+
+
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/push/PushState.uts b/uni_modules/uni-push/utssdk/app-android/push/PushState.uts
new file mode 100644
index 0000000000000000000000000000000000000000..c80852d5c975a9af825366fe6c71a6d723f0adf1
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/PushState.uts
@@ -0,0 +1,42 @@
+import Context from 'android.content.Context';
+import PackageManager from 'android.content.pm.PackageManager';
+import Bundle from 'android.os.Bundle';
+import TextUtils from 'android.text.TextUtils';
+export class PushState {
+
+ private static sMetaDatas : Bundle | null = null
+
+
+ static getAutoNotification() : boolean {
+ const context = UTSAndroid.getAppContext() as Context
+ const sp = context.getSharedPreferences("push_db_name", Context.MODE_PRIVATE)
+ const autoNotification = this.getMetaValue(context, "dcloud_unipush_auto_notification")
+ let needPush = true
+ if (autoNotification != null) {
+ if (!autoNotification.equals("ture", true)) {
+ needPush = false;
+ }
+ }
+ needPush = sp.getBoolean("auto_notification", needPush);
+ return needPush
+ }
+
+
+ private static getMetaValue(context : Context, metaKey : string) : string | null {
+ if (this.sMetaDatas == null) {
+ try {
+ this.sMetaDatas = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA).metaData;
+ } catch (e : Exception) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ if (this.sMetaDatas != null) {
+ const value = this.sMetaDatas!!.get(metaKey)
+ if (value != null && !TextUtils.isEmpty(value as string)) {
+ return value as string;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/push/utils/StringUtil.uts b/uni_modules/uni-push/utssdk/app-android/push/utils/StringUtil.uts
new file mode 100644
index 0000000000000000000000000000000000000000..97bc29a1408d4a5be16314cd31c4e18751147513
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/push/utils/StringUtil.uts
@@ -0,0 +1,31 @@
+export class StringUtil {
+ static trimString(pSrc : string, removed : string) : string {
+ const pTrimChar = removed.charAt(0)
+ let _ret = pSrc;
+ if (_ret != null && _ret != "") {
+ const _startPosi = _ret.charAt(0) == pTrimChar ? 1 : 0;
+ const _count = _ret.length;
+ const _endPosi = _ret.charAt(_count - 1) == pTrimChar ? _count - 1 : _count;
+ _ret = _ret.substring(_startPosi, _endPosi);
+ }
+ return _ret;
+ }
+
+ static getInt(content : string) : number | null {
+ try {
+ return content.toInt();
+ } catch (e : Exception) {
+ return null;
+ }
+ }
+
+
+ static getDouble(content : string) : number | null {
+ try {
+ return content.toDouble()
+ } catch (e : Exception) {
+ return null;
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push.png b/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push.png
new file mode 100755
index 0000000000000000000000000000000000000000..ed3d29bd26d2b611a328fba26aac73b44e916a10
Binary files /dev/null and b/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push.png differ
diff --git a/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push_small.png b/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push_small.png
new file mode 100755
index 0000000000000000000000000000000000000000..800dbd4a677f3c838095d7f31a4bc60ef85e75ed
Binary files /dev/null and b/uni_modules/uni-push/utssdk/app-android/res/drawable-xxhdpi/push_small.png differ
diff --git a/uni_modules/uni-push/utssdk/app-android/res/raw/keep.xml b/uni_modules/uni-push/utssdk/app-android/res/raw/keep.xml
new file mode 100644
index 0000000000000000000000000000000000000000..35edb41154a913b6042713dad4b709968f2b9970
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/res/raw/keep.xml
@@ -0,0 +1,7 @@
+
+
+
+ 消息推送
+ 推送消息
+
+
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-android/res/values/values.xml b/uni_modules/uni-push/utssdk/app-android/res/values/values.xml
new file mode 100644
index 0000000000000000000000000000000000000000..012adb5e607f5fee15fbdd8653591adaedf7a808
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/app-android/res/values/values.xml
@@ -0,0 +1,6 @@
+
+
+ unipush
+ message push
+
+
\ No newline at end of file
diff --git a/uni_modules/uni-push/utssdk/app-ios/index.uts b/uni_modules/uni-push/utssdk/app-ios/index.uts
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
diff --git a/uni_modules/uni-push/utssdk/interface.uts b/uni_modules/uni-push/utssdk/interface.uts
new file mode 100644
index 0000000000000000000000000000000000000000..84490f8ac43178f6aa5003271af83a36dff8e0d6
--- /dev/null
+++ b/uni_modules/uni-push/utssdk/interface.uts
@@ -0,0 +1,396 @@
+export interface Uni {
+ /**
+ * getPushClientId()
+ * @description
+ * 获取客户端唯一的推送标识
+ * @param {GetPushClientIdOptions}
+ * @return {void}
+ * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#getpushclientid
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ uni.getPushClientId({
+ complete: (res: any) => {
+ console.log("getPushClientId complete => " + JSON.stringify(res));
+ }
+ });
+ ```
+ */
+ getPushClientId(options : GetPushClientIdOptions) : void;
+ /**
+ * onPushMessage()
+ * @description
+ * 启动监听推送消息事件
+ * @param {OnPushMessageCallback}
+ * @return {void}
+ * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#onpushmessage
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ uni.onPushMessage((res : OnPushMessageCallbackResult) => {
+ console.log("onPushMessage => " + JSON.stringify(res))
+ });
+ ```
+ */
+ onPushMessage(callback : OnPushMessageCallback) : void;
+ /**
+ * offPushMessage()
+ * @description
+ * 关闭推送消息监听事件
+ * @param {OnPushMessageCallback}
+ * @return {void}
+ * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#offpushmessage
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ const cb = (res : OnPushMessageCallbackResult) => {
+ console.log("onPushMessage => " + JSON.stringify(res))
+ }
+ uni.offPushMessage(cb);
+ ```
+ */
+ offPushMessage(callback : OnPushMessageCallback) : void;
+ /**
+ * getChannelManager()
+ * @description
+ * 获取通知渠道管理器,Android 8系统以上才可以设置通知渠道,Android 8系统以下返回null。
+ * @param {void}
+ * @return {ChannelManager}
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "3.97",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ const channelManager = uni.getChannelManager();
+ channelManager.setPushChannel({
+ channelId: "test1",
+ channelDesc: "test1 desc",
+ soundName: "pushsound"
+ })
+ const channels = channelManager.getAllChannels() as string[]
+ console.log("channels : " + channels);
+ ```
+ */
+ getChannelManager() : ChannelManager;
+
+ /**
+ * createPushMessage()
+ * @description
+ * 创建本地通知栏消息
+ * @param {CreatePushMessageOptions}
+ * @return {void}
+ * @tutorial http://uniapp.dcloud.io/api/plugins/push.html#createpushmessage
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @example
+ ```typescript
+ uni.createPushMessage({
+ title:"hello",
+ content: "content"
+ });
+ ```
+ */
+ createPushMessage(options : CreatePushMessageOptions) : void;
+}
+
+export type GetPushClientId = (options : GetPushClientIdOptions) => void;
+export type GetPushClientIdSuccess = {
+ /**
+ * 个推客户端推送id,对应uni-id-device表的push_clientid
+ */
+ cid : string,
+ /**
+ * 错误描述
+ */
+ errMsg : string
+};
+export type GetPushClientIdSuccessCallback = (result : GetPushClientIdSuccess) => void;
+export type GetPushClientIdFail = UniError;
+export type GetPushClientIdFailCallback = (result : GetPushClientIdFail) => void;
+export type GetPushClientIdComplete = any;
+export type GetPushClientIdCompleteCallback = (result : GetPushClientIdComplete) => void;
+export type GetPushClientIdOptions = {
+ /**
+ * 接口调用成功的回调函数
+ * @defaultValue null
+ */
+ success : GetPushClientIdSuccessCallback | null,
+ /**
+ * 接口调用失败的回调函数
+ * @defaultValue null
+ */
+ fail : GetPushClientIdFailCallback | null,
+ /**
+ * 接口调用结束的回调函数(调用成功、失败都会执行)
+ * @defaultValue null
+ */
+ complete : GetPushClientIdCompleteCallback | null
+};
+/**
+ * 事件类型
+ * - click 从系统推送服务点击消息启动应用事件
+ * - receive 应用从推送服务器接收到推送消息事件
+ */
+export type OnPushMessageType = "click" | "receive";
+
+export type OnPushMessageCallbackResult = {
+ /**
+ * 事件类型
+ * @type{OnPushMessageType}
+ */
+ type : OnPushMessageType,
+ /**
+ * 消息内容
+ */
+ data : UTSJSONObject
+};
+
+export type OnPushMessageCallback = (result : OnPushMessageCallbackResult) => void;
+export type OnPushMessage = (callback : OnPushMessageCallback) => void;
+export type OffPushMessage = (callback : OnPushMessageCallback) => void;
+
+
+export type GetChannelManager = () => ChannelManager;
+export type SetPushChannelOptions = {
+ /**
+ * 添加的声音文件,注意raw目录下必须要有 ,不传此字段将使用默认铃音。
+ * @defaultValue null
+ */
+ soundName? : string | null,
+ /**
+ * 通知渠道id
+ */
+ channelId : string,
+ /**
+ * 通知渠道描述
+ */
+ channelDesc : string,
+ /**
+ * 呼吸灯闪烁
+ * @defaultValue false
+ */
+ enableLights? : boolean | null,
+ /**
+ * 震动
+ * @defaultValue false
+ */
+ enableVibration? : boolean | null,
+ /**
+ * 通知的重要性级别,可选范围IMPORTANCE_LOW:2、IMPORTANCE_DEFAULT:3、IMPORTANCE_HIGH:4 。
+ * @defaultValue 3
+ */
+ importance? : number | null,
+ /**
+ * 锁屏可见性,可选范围VISIBILITY_PRIVATE:0、VISIBILITY_PUBLIC:1、VISIBILITY_SECRET:-1、VISIBILITY_NO_OVERRIDE:-1000。
+ * @defaultValue -1000
+ */
+ lockscreenVisibility? : number | null
+}
+export interface ChannelManager {
+ /**
+ * 设置推送渠道
+ *
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+ setPushChannel(options : SetPushChannelOptions) : void;
+ /**
+ * 获取当前应用注册的所有的通知渠道。
+ *
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+ getAllChannels() : Array;
+}
+
+export type CreatePushMessage = (options : CreatePushMessageOptions) => void;
+export type CreatePushMessageSuccess = {};
+export type CreatePushMessageSuccessCallback = (result : CreatePushMessageSuccess) => void;
+export type CreatePushMessageFail = UniError;
+export type CreatePushMessageFailCallback = (result : CreatePushMessageFail) => void;
+export type CreatePushMessageComplete = any;
+export type CreatePushMessageCompleteCallback = (result : CreatePushMessageComplete) => void;
+export type CreatePushMessageOptions = {
+ /**
+ * 是否覆盖上一次提示的消息
+ * @type boolean
+ * @defaultValue false
+ */
+ cover? : boolean | null,
+ /**
+ * 提示消息延迟显示的时间,单位为s
+ * @defaultValue 0
+ */
+ delay? : number | null,
+ /**
+ * 推送消息的图标
+ * @defaultValue null
+ */
+ icon? : string | null,
+ /**
+ * 推送消息的提示音
+ * - system: 使用系统通知提示音(默认值)
+ * - none: 不使用提示音
+ * @type 'system' | 'none'
+ * @defaultValue "system"
+ */
+ sound? : string | null,
+ /**
+ * 推送消息的标题
+ * @defaultValue ""
+ */
+ title? : string | null,
+ /**
+ * 消息显示的内容,在系统通知中心中显示的文本内容
+ */
+ content : string,
+ /**
+ * 消息承载的数据,可根据业务逻辑自定义数据格式
+ * @defaultValue null
+ */
+ payload? : any | null,
+ /**
+ * 消息上显示的提示时间
+ * @defaultValue 当前时间
+ */
+ when? : number | null,
+ /**
+ * 渠道id
+ * @defaultValue "DcloudChannelID"
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+ channelId? : string | null,
+ /**
+ * 通知类别
+ * @defaultValue null
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4",
+ * "uniVer": "√",
+ * "unixVer": "3.97"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+ category? : string | null,
+ /**
+ * 接口调用成功的回调函数
+ * @defaultValue null
+ */
+ success : CreatePushMessageSuccessCallback | null,
+ /**
+ * 接口调用失败的回调函数
+ * @defaultValue null
+ */
+ fail : CreatePushMessageFailCallback | null,
+ /**
+ * 接口调用结束的回调函数(调用成功、失败都会执行)
+ * @defaultValue null
+ */
+ complete : CreatePushMessageCompleteCallback | null
+};
diff --git a/uni_modules/uni-storage/utssdk/interface.uts b/uni_modules/uni-storage/utssdk/interface.uts
index 68f6b0774d95150d310575bb0f54940f63d2a16f..e94b9a2d6ee44f5b67299df1af819e4679bf437b 100644
--- a/uni_modules/uni-storage/utssdk/interface.uts
+++ b/uni_modules/uni-storage/utssdk/interface.uts
@@ -244,9 +244,9 @@ export type ClearStorageSync = () => void
export interface Uni {
/**
* uni.setStorage函数定义
- * 将数据存储在本地storage存储中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个异步接口。
- *
- * @param {SetStorageOptions} options
+ * 将数据存储在本地storage存储中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个异步接口。
+ *
+ * @param {SetStorageOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#setstorage
* @uniPlatform {
* "app": {
@@ -258,7 +258,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -269,7 +269,7 @@ export interface Uni {
/**
* uni.setStorageSync函数定义
* 将 data 存储在本地storage存储中指定的 key 中,会覆盖掉原来该 key 对应的内容,这是一个同步接口。
- *
+ *
* @param {string} key 本地storage存储中的指定的 key
* @param {any} data 需要存储的内容,只支持原生类型、及能够通过 JSON.stringify 序列化的对象
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#setstoragesync
@@ -283,7 +283,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -294,20 +294,20 @@ export interface Uni {
/**
* uni.getStorage函数定义
* 从本地存储中异步获取指定 key 对应的内容。
- *
- * @param {GetStorageOptions} options
+ *
+ * @param {GetStorageOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#getstorage
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -318,7 +318,7 @@ export interface Uni {
/**
* uni.getStorageSync函数定义
* 从本地存储中同步获取指定 key 对应的内容。
- *
+ *
* @param {string} key 本地存储中的指定的 key
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#getstoragesync
* @uniPlatform {
@@ -331,7 +331,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -342,8 +342,8 @@ export interface Uni {
/**
* uni.getStorageInfo函数定义
* 异步获取当前 storage 的相关信息。
- *
- * @param {GetStorageInfoOptions} options
+ *
+ * @param {GetStorageInfoOptions} options
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#getstorageinfo
* @uniPlatform {
* "app": {
@@ -355,7 +355,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -366,10 +366,10 @@ export interface Uni {
/**
* uni.getStorageInfoSync函数定义
* 同步获取当前 storage 的相关信息。
- *
- *
+ *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#getstorageinfosync
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -380,7 +380,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -391,11 +391,11 @@ export interface Uni {
/**
* uni.removeStorage函数定义
* 从本地存储中异步移除指定 key。
- *
- * @param {RemoveStorageOptions} options
- *
+ *
+ * @param {RemoveStorageOptions} options
+ *
* @tutorial hhttps://uniapp.dcloud.net.cn/api/storage/storage.html#removestorage
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -406,7 +406,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -417,11 +417,11 @@ export interface Uni {
/**
* uni.removeStorageSync函数定义
* 从本地存储中同步移除指定 key。
- *
+ *
* @param {string} key 本地存储中的指定的 key
- *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#removestoragesync
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -432,7 +432,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -443,9 +443,9 @@ export interface Uni {
/**
* uni.clearStorage函数定义
* 清除本地数据存储。
- *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#clearstorage
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -456,7 +456,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -467,9 +467,9 @@ export interface Uni {
/**
* uni.clearStorageSync函数定义
* 清除本地数据存储。
- *
+ *
* @tutorial https://uniapp.dcloud.net.cn/api/storage/storage.html#clearstoragesync
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -480,7 +480,7 @@ export interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "2.0.3",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
diff --git a/uni_modules/uni-usercapturescreen/index.d.ts b/uni_modules/uni-usercapturescreen/index.d.ts
index debf1a1d781a14f5ef58dec089a42786b7ad837a..dbb3f929122ab33841008ec9774259e70987cdb0 100644
--- a/uni_modules/uni-usercapturescreen/index.d.ts
+++ b/uni_modules/uni-usercapturescreen/index.d.ts
@@ -1,18 +1,157 @@
declare namespace UniNamespace {
- type OnUserCaptureScreenCallback = (res?: { errMsg: string }) => void
+ /**
+ * uni.onUserCaptureScreen/uni.offUserCaptureScreen回调参数
+ */
+ type OnUserCaptureScreenCallbackResult = {
+ /**
+ * 截屏文件路径(仅Android返回)
+ */
+ path ?: string
+ }
+
+ /**
+ * uni.onUserCaptureScreen/uni.offUserCaptureScreen回调函数定义
+ */
+ type UserCaptureScreenCallback = (res : OnUserCaptureScreenCallbackResult) => void
+
+ type OnUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
+
+ type OffUserCaptureScreen = (callback : UserCaptureScreenCallback | null) => void
+
+ /**
+ * uni.setUserCaptureScreen成功回调参数
+ */
+ type SetUserCaptureScreenSuccess = {
+
+ }
+
+ /**
+ * uni.setUserCaptureScreen成功回调函数定义
+ */
+ type SetUserCaptureScreenSuccessCallback = (res : SetUserCaptureScreenSuccess) => void
+
+ /**
+ * 错误码
+ * - 12001 "setUserCaptureScreen:system not support"
+ * - 12010 "setUserCaptureScreen:system internal error"
+ */
+ type SetUserCaptureScreenErrorCode = 12001 | 12010;
+
+ /**
+ * SetUserCaptureScreen 的错误回调参数
+ */
+ interface SetUserCaptureScreenFail {
+ errCode : SetUserCaptureScreenErrorCode
+ }
+
+ /**
+ * uni.setUserCaptureScreen失败回调函数定义
+ */
+ type SetUserCaptureScreenFailCallback = (res : SetUserCaptureScreenFail) => void
+
+ /**
+ * uni.setUserCaptureScreen完成回调函数定义
+ */
+ type SetUserCaptureScreenCompleteCallback = (res : any) => void
+
+ /**
+ * uni.setUserCaptureScreen参数
+ */
+ type SetUserCaptureScreenOptions = {
+ /**
+ * true: 允许用户截屏 false: 不允许用户截屏,防止用户截屏到应用页面内容
+ */
+ enable : boolean;
+ /**
+ * 接口调用成功的回调函数
+ */
+ // success : SetUserCaptureScreenSuccessCallback | null,
+ success ?: SetUserCaptureScreenSuccessCallback,
+ /**
+ * 接口调用失败的回调函数
+ */
+ // fail : SetUserCaptureScreenFailCallback | null,
+ fail ?: SetUserCaptureScreenFailCallback,
+ /**
+ * 接口调用结束的回调函数(调用成功、失败都会执行)
+ */
+ // complete : SetUserCaptureScreenSuccessCallback | SetUserCaptureScreenFailCallback | null
+ complete ?: SetUserCaptureScreenCompleteCallback
+ }
+
+ type SetUserCaptureScreen = (options : SetUserCaptureScreenOptions) => void
}
declare interface Uni {
/**
- * 监听用户主动截屏事件,用户使用系统截屏按键截屏时触发此事件。
+ * 开启截屏监听
+ *
+ * @param {UserCaptureScreenCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ onUserCaptureScreen(callback : UniNamespace.UserCaptureScreenCallback | null) : void,
+ /**
+ * 关闭截屏监听
*
- * 文档: [https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#onusercapturescreen)
+ * @param {UserCaptureScreenCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
*/
- onUserCaptureScreen(callback: UniNamespace.OnUserCaptureScreenCallback): void;
+ offUserCaptureScreen(callback : UniNamespace.UserCaptureScreenCallback | null) : void,
/**
- * 用户主动截屏事件。取消事件监听。
+ * 设置防截屏
*
- * 文档: [https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen](https://uniapp.dcloud.net.cn/api/system/capture-screen.html#offusercapturescreen)
+ * @param {SetUserCaptureScreenOptions} options
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/capture-screen.html#setusercapturescreen
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "13.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
*/
- offUserCaptureScreen(callback: UniNamespace.OnUserCaptureScreenCallback): void;
+ setUserCaptureScreen(options : UniNamespace.SetUserCaptureScreenOptions) : void
}
diff --git a/uni_modules/uni-usercapturescreen/package.json b/uni_modules/uni-usercapturescreen/package.json
index 6b099cfa62b02781730789c0102b698f2305ddd3..c55c0f8c8fa27f63b93a7d4cc1e19c67ae22795a 100644
--- a/uni_modules/uni-usercapturescreen/package.json
+++ b/uni_modules/uni-usercapturescreen/package.json
@@ -54,7 +54,7 @@
},
"client": {
"Vue": {
- "vue2": "n",
+ "vue2": "y",
"vue3": "y"
},
"App": {
diff --git a/uni_modules/uni-wifi/utssdk/app-android/index.uts b/uni_modules/uni-wifi/utssdk/app-android/index.uts
index 40312b401248242f92eb46fd6c7bd3c3030dbc06..bef663a5624524e8d50f9a7fc96787f563467932 100644
--- a/uni_modules/uni-wifi/utssdk/app-android/index.uts
+++ b/uni_modules/uni-wifi/utssdk/app-android/index.uts
@@ -1,5 +1,4 @@
import Context from "android.content.Context";
-import { UTSAndroid } from "io.dcloud.uts";
import WifiManager from "android.net.wifi.WifiManager";
import WifiInfo from "android.net.wifi.WifiInfo";
import Manifest from "android.Manifest";
@@ -8,9 +7,7 @@ import ScanResult from "android.net.wifi.ScanResult";
import BroadcastReceiver from "android.content.BroadcastReceiver";
import ActivityCompat from "androidx.core.app.ActivityCompat";
import IntentFilter from "android.content.IntentFilter";
-import JSONObject from "com.alibaba.fastjson.JSONObject";
import Intent from "android.content.Intent";
-import Thread from "java.lang.Thread";
import WifiConfiguration from 'android.net.wifi.WifiConfiguration';
import AuthAlgorithm from 'android.net.wifi.WifiConfiguration.AuthAlgorithm';
@@ -18,8 +15,8 @@ import KeyMgmt from 'android.net.wifi.WifiConfiguration.KeyMgmt';
import TextUtils from 'android.text.TextUtils';
import Build from 'android.os.Build';
-import { UniWifiResult, GetConnectedWifiOptions, WifiConnectOption, WifiOption, UniWifiInfo } from "../interface.uts"
-
+import { UniWifiResult, UniWifiInfoWithPartialInfo,GetConnectedWifiOptions, WifiConnectOption, WifiOption, UniWifiInfo,UniWifiCallback ,UniWifiResultCallback,UniWifiResultCallbackWithPartialInfo,UniGetWifiListCallback} from "../interface.uts"
+import { WifiFailImpl, getErrcode,UniErrorSubject } from '../unierror';
/**
@@ -32,12 +29,12 @@ class Global {
// 扫描wifi结果
static scanList : AndroidUniWifiInfo[] = []
// 获取wifi列表监听
- static onGetWifiListCallback : UTSCallback | null = null
- static supendGetWifiSuccess : ((res: UniWifiResult) => void) | null = null
- static supendGetWifiComplete : ((res: UniWifiResult) => void) | null = null
+ static onGetWifiListCallback : UniGetWifiListCallback|null = null
+ static supendGetWifiSuccess : UniWifiResultCallback|null = null
+ static supendGetWifiComplete :UniWifiResultCallback|null = null
// wifi链接监听
- static onWifiConnectCallbackList : UTSCallback[] = []
- static onWifiConnectWithPartialInfoCallbackList : UTSCallback[] = []
+ static onWifiConnectCallbackList : UniWifiResultCallback[] = []
+ static onWifiConnectWithPartialInfoCallbackList : UniWifiResultCallbackWithPartialInfo[] = []
}
@@ -256,46 +253,37 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.WIFI_STATE_CHANGED_ACTION) {
+
let state =
intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN)
+
if (state == WifiManager.WIFI_STATE_ENABLED) {
// 获取当前的connectInfo 并且进行数据封装
- // let uniWifiInfo = new UniWifiInfo(null)
- let uniWifiInfo : UniWifiInfo = {
- SSID: "",
- secure: false,
- signalStrength: 0,
- frequency: 0,
- }
+ let uniWifiInfo = new UniWifiInfo("","",false,0,0)
//做一些异步操作
setTimeout(function () {
// BroadcastReceiver 中不能执行耗时任务,需要使用setTimeout
// @ts-ignore
let winfo = this.mWifiManager!.getConnectionInfo();
- while (winfo.bssid == null || zeroCountNum(winfo.bssid) > 4) {
- Thread.sleep(1000)
- winfo = this.mWifiManager!.getConnectionInfo();
- }
-
- // 封装成数据对象
- uniWifiInfo = wrapUniWifiInfoFromConnectInfo(winfo)
- let res = {
- errMsg: 'onWifiConnected:ok',
- errCode: 0,
- wifi: uniWifiInfo
- }
- // wifi状态可用了,分发当前的链接状态给已注册的监听集合
- for (let perCallback in Global.onWifiConnectCallbackList) {
- perCallback(res);
- }
- // 封装仅SSID 数据对象
- var connectedWithPartialInfo = {
- SSID: uniWifiInfo.SSID
- }
- for (let perCallback in Global.onWifiConnectWithPartialInfoCallbackList) {
- perCallback(connectedWithPartialInfo);
- }
+ if(winfo != null && winfo.bssid != null && zeroCountNum(winfo.bssid) < 3){
+ // 当前设备链接到了某个具体的wifi.封装成数据对象
+ uniWifiInfo = wrapUniWifiInfoFromConnectInfo(winfo)
+ let res = new UniWifiResult(0,UniErrorSubject,'onWifiConnected:ok',uniWifiInfo)
+
+ // wifi状态可用了,分发当前的链接状态给已注册的监听集合
+ for (let perCallback in Global.onWifiConnectCallbackList) {
+ perCallback(res);
+ }
+ // 封装仅SSID 数据对象
+ let connectedWithPartialInfo = new UniWifiInfoWithPartialInfo(uniWifiInfo.SSID)
+
+ for (let perCallback in Global.onWifiConnectWithPartialInfoCallbackList) {
+ perCallback(connectedWithPartialInfo);
+ }
+ } else {
+ // 开启了wifi 开关,但是尚未链接到某个具体的wifi
+ }
}, 100);
}
@@ -305,14 +293,9 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
if (intent.action == WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) {
startWifiScaning = false;
-
-
-
-
// wifi 扫描结果回调
let results = this.mWifiManager!.scanResults;
-
if (results != null) {
Global.scanList = []
for (let scanResult in results) {
@@ -324,7 +307,7 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
// 挨个通知,所有的监听器
if(Global.onGetWifiListCallback != null){
- const data = new JSONObject();
+ const data = new UTSJSONObject();
data["wifiList"] = Global.scanList
Global.onGetWifiListCallback?.(data);
/**
@@ -335,11 +318,7 @@ class CustomBroadcastReceiver extends BroadcastReceiver {
}
- let ret : UniWifiResult = {
- errCode: 0,
- errSubject: "uni-getWifiList",
- errMsg: "getWifiList:ok"
- }
+ let ret = new UniWifiResult(0,UniErrorSubject,"getWifiList:ok",null)
if(Global.supendGetWifiSuccess != null){
Global.supendGetWifiSuccess?.(ret)
Global.supendGetWifiSuccess = null
@@ -365,89 +344,85 @@ var startWifiScaning = false
* 开启wifi
*/
@Suppress("DEPRECATION")
-export function startWifi(option : WifiOption) {
-
- // 需要先开启wifi,才能使用后续的功能
- let requestCode = 1001;
- let permissionWifi = arrayOf("android.permission.ACCESS_FINE_LOCATION");
-
- let result : UniWifiResult = {
- errCode: 12001,
- errMsg: "startWifi:premission loss",
- errSubject: "uni-startWifi"
- }
-
- // 检查权限
- if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
-
- ActivityCompat.requestPermissions(UTSAndroid.getUniActivity()!, permissionWifi, requestCode.toInt())
- // 尚不具备权限,返回错误
- let err = new UniError("uni-startWifi",12001,"startWifi:premission loss");
- option.fail?.(err)
- option.complete?.(err)
+export function startWifiImpl(option : WifiOption) {
+
+
+ // 具备了权限,继续前进
+ let wifiManager : WifiManager =
+ UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
+ // 用户没有开启wifi 总开关
+ if (!wifiManager.isWifiEnabled()) {
+ // wifi 没开启
+ let failResult = new WifiFailImpl(getErrcode(12005));
+ option.fail?.(failResult);
+ option.complete?.(failResult);
+ return;
+ }
+ // 初始化wifi 状态广播监听,后续所有的api,均基于此
+ if(Global.mReceiver != null){
+ // 说明已经注册过了
+ let result = UniWifiResult(0,UniErrorSubject,"startWifi:ok",null)
+
+ option.success?.(result)
+ option.complete?.(result)
+ return
+ }
+
+
+ Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
+
+ let filter = new IntentFilter()
+ filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
+ // @ts-ignore
+ filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION)
+ // @ts-ignore
+ filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+
+ UTSAndroid.getUniActivity()!.registerReceiver(Global.mReceiver, filter)
+
+ /**
+ * activity 被销毁时,取消注册
+ */
+ UTSAndroid.onAppActivityDestroy(function () {
+
+ if (Global.mReceiver != null) {
+ UTSAndroid.getUniActivity()!.unregisterReceiver(Global.mReceiver)
+ Global.mReceiver = null
+
+ Global.scanList = []
+ Global.onGetWifiListCallback = null
+ Global.onWifiConnectCallbackList = []
+ Global.onWifiConnectWithPartialInfoCallbackList = []
+ }
+
+ });
+ startWifiScaning = true
+ // 开始扫描
+ wifiManager.startScan()
+
+ let result = UniWifiResult(0,UniErrorSubject,"startWifi:ok",null)
+ option.success?.(result)
+ option.complete?.(result)
- return;
- }
-
- // 具备了权限,继续前进
- let wifiManager : WifiManager =
- UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
- // 用户没有开启wifi 总开关
- if (!wifiManager.isWifiEnabled()) {
- // wifi 没开启
- let err = new UniError("uni-startWifi",12005,"wifi not turned on");
- option.fail?.(err);
- option.complete?.(err);
- return;
- }
- // 初始化wifi 状态广播监听,后续所有的api,均基于此
- if(Global.mReceiver != null){
- // 说明已经注册过了
- result.errCode = 0
- result.errMsg = "startWifi:ok"
-
- option.success?.(result)
- option.complete?.(result)
- return
- }
-
-
- Global.mReceiver = new CustomBroadcastReceiver(wifiManager)
-
- let filter = new IntentFilter()
- filter.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)
- // @ts-ignore
- filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION)
- // @ts-ignore
- filter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
-
- UTSAndroid.getUniActivity()!.registerReceiver(Global.mReceiver, filter)
-
- /**
- * activity 被销毁时,取消注册
- */
- UTSAndroid.onAppActivityDestroy(function () {
-
- if (Global.mReceiver != null) {
- UTSAndroid.getUniActivity()!.unregisterReceiver(Global.mReceiver)
- Global.mReceiver = null
-
- Global.scanList = []
- Global.onGetWifiListCallback = null
- Global.onWifiConnectCallbackList = []
- Global.onWifiConnectWithPartialInfoCallbackList = []
- }
-
- });
- startWifiScaning = true
- // 开始扫描
- wifiManager.startScan()
+}
- result.errCode = 0
- result.errMsg = "startWifi:ok"
+@Suppress("DEPRECATION")
+export function startWifi(option : WifiOption) {
- option.success?.(result)
- option.complete?.(result)
+ /**
+ * 准备权限
+ */
+ let permissionNeed = ["android.permission.ACCESS_FINE_LOCATION"];
+ UTSAndroid.requestSystemPermission(UTSAndroid.getUniActivity()!, permissionNeed, function (allRight:boolean,_grantedList:string[]) {
+ if (allRight) {
+ // 交给目前的location 引擎,真实执行
+ startWifiImpl(option)
+ }
+ }, function (_doNotAskAgain:boolean,_grantedList:string[]) {
+ let err = new WifiFailImpl(getErrcode(12001));
+ option.fail?.(err)
+ option.complete?.(err)
+ })
}
@@ -460,8 +435,7 @@ export function getWifiList(option : WifiOption) {
if (Global.mReceiver == null) {
// 还没调用startWifi 提示报错
- let err = new UniError("uni-getWifiList",12000,"getWifiList:fail:not invoke startWifi");
-
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
@@ -471,13 +445,14 @@ export function getWifiList(option : WifiOption) {
let wifiManager : WifiManager =
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
+ if(option.success != null){
+ Global.supendGetWifiSuccess = option.success
+ }
+ if(option.complete != null){
+ Global.supendGetWifiComplete = option.complete
+ }
-
- Global.supendGetWifiSuccess = option.success
- Global.supendGetWifiComplete = option.complete
-
wifiManager.startScan()
-
}
@@ -486,12 +461,12 @@ export function getWifiList(option : WifiOption) {
/**
* wifi 链接成功的回调注册
*/
-export function onWifiConnected(callback : UTSCallback) {
+export function onWifiConnected(callback : UniWifiResultCallback) {
Global.onWifiConnectCallbackList.push(callback)
}
-export function onWifiConnectedWithPartialInfo(callback : UTSCallback) {
+export function onWifiConnectedWithPartialInfo(callback : UniWifiResultCallbackWithPartialInfo) {
Global.onWifiConnectWithPartialInfoCallbackList.push(callback)
}
@@ -499,13 +474,13 @@ export function onWifiConnectedWithPartialInfo(callback : UTSCallback) {
/**
* wifi 链接成功的回调取消注册
*/
-export function offWifiConnected(callback? : UTSCallback) {
-
+export function offWifiConnected(callback? : UniWifiResultCallback) {
+
if(callback == null){
Global.onWifiConnectCallbackList = []
return
}
-
+
let callbackIndex = Global.onWifiConnectCallbackList.indexOf(callback)
if (callbackIndex >= 0) {
Global.onWifiConnectCallbackList.splice(callbackIndex, 1);
@@ -515,13 +490,13 @@ export function offWifiConnected(callback? : UTSCallback) {
/**
* 不具备详细信息的wifi 反注册
*/
-export function offWifiConnectedWithPartialInfo(callback? : UTSCallback) {
-
+export function offWifiConnectedWithPartialInfo(callback? : UniWifiResultCallbackWithPartialInfo) {
+
if(callback == null){
Global.onWifiConnectWithPartialInfoCallbackList = []
return
}
-
+
let callbackIndex = Global.onWifiConnectWithPartialInfoCallbackList.indexOf(callback)
if (callbackIndex >= 0) {
Global.onWifiConnectWithPartialInfoCallbackList.splice(callbackIndex, 1);
@@ -531,14 +506,14 @@ export function offWifiConnectedWithPartialInfo(callback? : UTSCallback) {
/**
* 注册Wifi列表的监听事件
*/
-export function onGetWifiList(callback : UTSCallback) {
+export function onGetWifiList(callback : UniGetWifiListCallback) {
Global.onGetWifiListCallback = callback
}
/**
* 取消注册Wifi列表的监听事件
*/
-export function offGetWifiList(callback? : UTSCallback) {
+export function offGetWifiList(callback? : UniWifiCallback) {
Global.onGetWifiListCallback = null
Global.supendGetWifiComplete = null
Global.supendGetWifiSuccess = null
@@ -549,16 +524,16 @@ export function offGetWifiList(callback? : UTSCallback) {
* 真正执行wifi链接逻辑
*/
function realWifiConnect(option : WifiConnectOption){
-
+
if (Global.mReceiver == null || Global.scanList.length < 1) {
-
- let err = new UniError("uni-connectWifi",12000,"connectWifi:fail:not invoke startWifi");
+
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
-
+
return
}
-
+
// 执行后续的逻辑
let scanWifiInfo : AndroidUniWifiInfo | null = null
for (let scanResult in Global.scanList) {
@@ -566,20 +541,20 @@ function realWifiConnect(option : WifiConnectOption){
scanWifiInfo = scanResult
}
}
-
+
if (scanWifiInfo == null) {
// 不在扫描列表中返回错误
- let err = new UniError("uni-connectWifi",12000,"connectWifi:fail:not invoke startWifi");
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
return
}
-
+
let wifiConfigration = wrapWifiConfiguration(scanWifiInfo.SSID, option.password, scanWifiInfo.securityType);
wifiConfigration.BSSID = scanWifiInfo.BSSID
let wifiManager : WifiManager =
UTSAndroid.getAppContext()!.getSystemService(Context.WIFI_SERVICE) as WifiManager
-
+
// 如果已经存在了指定wifi 配置,移除之
let targetExistConfig : WifiConfiguration | null = null
let existingConfigs = wifiManager.getConfiguredNetworks();
@@ -591,28 +566,28 @@ function realWifiConnect(option : WifiConnectOption){
// 如果wifi已经保存了当前ssid的配置,可能是别的应用添加的。android系统要求,需要删除掉重新添加
if (targetExistConfig != null) {
let removeRet = wifiManager.removeNetwork(targetExistConfig.networkId);
-
+
if (!removeRet) {
-
+
// add since 2023-03-28,如果当前系统大于等于android10, 则明确当前系统不支持
if(Build.VERSION.SDK_INT > 28){
// 系统大于android 9
- let err = new UniError("uni-connectWifi",12001,"connectWifi:system not support");
+ let err = new WifiFailImpl(getErrcode(12001));
option.fail?.(err)
option.complete?.(err)
}else{
// 移除之前的配置失败了,返回错误,需要用户手动取消保存一下
- let err = new UniError("uni-connectWifi",12013,"connectWifi:wifi config may be expired");
+ let err = new WifiFailImpl(getErrcode(12013));
option.fail?.(err)
option.complete?.(err)
}
-
-
+
+
return
}
-
+
}
-
+
let currentConnect = wifiManager.getConnectionInfo()
if (currentConnect.networkId >= 0) {
wifiManager.disableNetwork(currentConnect.networkId)
@@ -620,55 +595,47 @@ function realWifiConnect(option : WifiConnectOption){
wifiManager.removeNetwork(currentConnect.networkId)
}
wifiManager.disconnect()
-
+
let connected = false;
try {
-
+
let netID = wifiManager.addNetwork(wifiConfigration);
// 如果-1 说明没添加上,报错即可
if (netID < 0) {
-
- let err = new UniError("uni-connectWifi",12002,"connectWifi:password error Wi-Fi");
-
+ let err = new WifiFailImpl(getErrcode(12002));
option.fail?.(err)
option.complete?.(err)
-
+
return
}
-
-
+
+
let enabled = wifiManager.enableNetwork(netID, true);
if (!enabled) {
-
- let err = new UniError("uni-connectWifi",12007,"connectWifi:user denied");
-
+ let err = new WifiFailImpl(getErrcode(12007));
option.fail?.(err)
option.complete?.(err)
-
+
return
}
connected = wifiManager.reconnect();
-
+
} catch (e) {
connected = false;
console.log(e);
}
-
+
if (!connected) {
// 出错了,返回错误
// 兜底的报错
- let err = new UniError("uni-connectWifi",12010,"connectWifi:fail:unknown error");
+ let err = new WifiFailImpl(getErrcode(12010));
option.fail?.(err)
option.complete?.(err)
return
}
-
- let result : UniWifiResult = {
- errCode: 0,
- errMsg: "connectWifi:ok",
- errSubject: "uni-connectWifi",
- }
-
+
+ let result = new UniWifiResult(0,UniErrorSubject,"getWifiList:ok",null)
+
wifiManager.saveConfiguration()
//scanWifiInfo 根据 partialInfo 填充给返回字段
if (option.partialInfo != null && option.partialInfo == true) {
@@ -679,8 +646,8 @@ function realWifiConnect(option : WifiConnectOption){
} else {
result.wifi = wrapUniWifiInfoFromAndroid(scanWifiInfo)
}
-
-
+
+
option.success?.(result)
option.complete?.(result)
}
@@ -696,25 +663,22 @@ export function connectWifi(option : WifiConnectOption) {
let manunalIntent = new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS);
UTSAndroid.getUniActivity()!.startActivity(manunalIntent);
- let result : UniWifiResult = {
- errCode: 0,
- errMsg: "connectWifi:ok",
- errSubject: "uni-connectWifi",
- }
+
+ let result = new UniWifiResult(0,UniErrorSubject,"connectWifi:ok",null)
option.success?.(result)
option.complete?.(result)
return
}
-
-
+
+
// add since 2022-03-28 ,增加逻辑,如果正在扫描中,则可以等待5s
if(startWifiScaning){
let taskCount = 0
let taskId:number = 0
taskId = setInterval(function(){
-
+
taskCount += 1;
if(taskCount >= 5 || startWifiScaning == false){
// 超过10s了。或者扫描过程结束了
@@ -722,7 +686,7 @@ export function connectWifi(option : WifiConnectOption) {
realWifiConnect(option)
}
},2000)
-
+
UTSAndroid.onAppActivityDestroy(function () {
clearInterval(taskId)
});
@@ -730,7 +694,7 @@ export function connectWifi(option : WifiConnectOption) {
realWifiConnect(option)
}
-
+
}
@@ -741,7 +705,7 @@ export function connectWifi(option : WifiConnectOption) {
export function stopWifi(option : WifiOption) {
// 需要先开启wifi,才能使用后续的功能
if (Global.mReceiver == null) {
- let err = new UniError("uni-stopWifi",12000,"stopWifi:not init");
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
@@ -753,20 +717,15 @@ export function stopWifi(option : WifiOption) {
// 多次调用
//TODO handle the exception
}
-
+
Global.onGetWifiListCallback = null
Global.onWifiConnectWithPartialInfoCallbackList = []
Global.onWifiConnectCallbackList = []
Global.mReceiver = null
-
- let result : UniWifiResult = {
- errCode: 0,
- errSubject: "uni-stopWifi",
- errMsg: "stopWifi:ok"
- }
- option.success?.(result)
- option.complete?.(result)
+ let ret = new UniWifiResult(0,UniErrorSubject,"stopWifi:ok",null)
+ option.success?.(ret)
+ option.complete?.(ret)
}
@@ -780,10 +739,10 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
SSID: ""
}
-
+
if (Global.mReceiver == null) {
// 还没调用startWifi 提示报错
- let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:fail:not invoke startWifi");
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
@@ -793,14 +752,14 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
// 需要先校验权限,没有位置权限无法获取wifi
if (ActivityCompat.checkSelfPermission(UTSAndroid.getUniActivity()!, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// 尚不具备权限,返回错误
- let err = new UniError("uni-getConnectedWifi",12001,"getConnectedWifi:permission loss");
+ let err = new WifiFailImpl(getErrcode(12001));
option.fail?.(err)
option.complete?.(err)
return;
}
-
-
+
+
const context = UTSAndroid.getAppContext();
if (context != null) {
const wm = context.getSystemService(
@@ -811,12 +770,8 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
const winfo = wm.getConnectionInfo();
wifiInfo = wrapUniWifiInfoFromConnectInfo(winfo);
-
- let res : UniWifiResult = {
- errCode: 0,
- errMsg: "getConnectedWifi:ok",
- errSubject: "uni-getConnectedWifi",
- }
+
+ let res = new UniWifiResult(0,UniErrorSubject,"getConnectedWifi:ok",null)
// 判断一下是否wifi 关闭了
if (option.partialInfo!= null) {
@@ -826,7 +781,7 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
res.wifi = ret;
} else {
if (wifiInfo.BSSID == null || zeroCountNum(wifiInfo.BSSID) > 3) {
- let err = new UniError("uni-getConnectedWifi",12005,"getConnectedWifi:fail:wifi is disable");
+ let err = new WifiFailImpl(getErrcode(12005));
option.fail?.(err)
option.complete?.(err)
return
@@ -839,8 +794,8 @@ export function getConnectedWifi(option : GetConnectedWifiOptions) {
option.complete?.(res)
return
}
-
- let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:fail:not invoke startWifi");
+
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
}
diff --git a/uni_modules/uni-wifi/utssdk/app-ios/index.uts b/uni_modules/uni-wifi/utssdk/app-ios/index.uts
index a2ccfe4e1427ea14500bc41a2a1c0b0b1502e9be..f2bdb50dec0ca28eea7bb55e59ac7362ca9a21cd 100644
--- a/uni_modules/uni-wifi/utssdk/app-ios/index.uts
+++ b/uni_modules/uni-wifi/utssdk/app-ios/index.uts
@@ -3,20 +3,21 @@ import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'S
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
-import { WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OnOffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
+import { UniWifiResultCallbackWithPartialInfo, UniGetWifiListCallback, UniWifiResultCallback, WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
+import { WifiFailImpl, getErrcode } from '../unierror';
-/*
+/*
* 系统定位权限获取类
*/
class LocationPromiseService implements CLLocationManagerDelegate {
static promiseCompletionHandler: ((res: boolean)=>void)[] = []
-
+
manager?: CLLocationManager
-
+
constructor(manager?: CLLocationManager) {
this.manager = manager
}
-
+
initlizeManager(): boolean {
if (this.manager == null) {
this.manager = new CLLocationManager()
@@ -24,20 +25,20 @@ class LocationPromiseService implements CLLocationManagerDelegate {
}
return true
}
-
+
locationManager(manager: CLLocationManager, @argumentLabel("didChangeAuthorization") status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(true)
})
- } else if (status == CLAuthorizationStatus.notDetermined) {
+ } else if (status == CLAuthorizationStatus.notDetermined) {
manager.requestWhenInUseAuthorization()
} else if (status == CLAuthorizationStatus.denied) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(false)
})
}
- }
+ }
requestPromise(@escaping completion: (res: boolean)=>void) {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if (status == CLAuthorizationStatus.notDetermined) {
@@ -52,20 +53,20 @@ class LocationPromiseService implements CLLocationManagerDelegate {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
- }
+ }
}
}
const locationPromiseService: LocationPromiseService = new LocationPromiseService(null)
-/*
- * 获取系统定位权限
+/*
+ * 获取系统定位权限
*/
function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
locationPromiseService.requestPromise(completion)
}
-/*
+/*
* 获取当前连接的wifi信息(通过定位权限)
*/
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
@@ -76,20 +77,20 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
secure: false,
signalStrength: 0,
frequency: 0
- }
-
+ }
+
if (arr != null) {
let list = arr! as NSArray
let index: Int = 0
- while (index < list.count) {
- let item = list[index]
+ while (index < list.count) {
+ let item = list[index]
let interfaceName = item as string
let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString)
if (dic != null) {
let dict = dic! as NSDictionary
- let SSID = dict[kCNNetworkInfoKeySSID as string]
+ let SSID = dict[kCNNetworkInfoKeySSID as string]
let BSSID = dict[kCNNetworkInfoKeyBSSID as string]
-
+
if (SSID != null && BSSID != null) {
let ssid = SSID! as string
let bssid = BSSID! as string
@@ -103,7 +104,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
}
index++
}
-
+
if (wifiInfo.BSSID!.length > 0 && wifiInfo.SSID.length > 0) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
@@ -114,12 +115,12 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
option.success?.(res)
option.complete?.(res)
}else {
- let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error");
+ let err = new WifiFailImpl(getErrcode(12010));
option.fail?.(err)
option.complete?.(err)
}
}else {
- let err = new UniError("uni-getConnectedWifi",12010,"getConnectedWifi:system internal error");
+ let err = new WifiFailImpl(getErrcode(12010));
option.fail?.(err)
option.complete?.(err)
}
@@ -127,7 +128,7 @@ function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions)
-/*
+/*
* 保存全局数据信息
*/
class UniWiFiModuleGloabInfo {
@@ -138,14 +139,14 @@ class UniWiFiModuleGloabInfo {
-/*
- * 初始化wifi模块
+/*
+ * 初始化wifi模块
*/
export const startWifi: StartWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res: UniWifiResult = {
errSubject: "uni-startWifi",
- errCode: 0,
+ errCode: 0,
errMsg: "startWifi:ok",
wifi: null
}
@@ -153,15 +154,15 @@ export const startWifi: StartWifi = function (option: WifiOption) {
option.complete?.(res)
}
-/*
- * 停止wifi模块
+/*
+ * 停止wifi模块
*/
export const stopWifi: StopWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false
- LocationPromiseService.promiseCompletionHandler = []
+ LocationPromiseService.promiseCompletionHandler = []
let res: UniWifiResult = {
errSubject: "uni-stopWifi",
- errCode: 0,
+ errCode: 0,
errMsg: "stopWifi:ok",
wifi: null
}
@@ -169,11 +170,11 @@ export const stopWifi: StopWifi = function (option: WifiOption) {
option.complete?.(res)
}
-/*
+/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
export const getWifiList: GetWifiList = function (option: WifiOption) {
- let err = new UniError("uni-getWifiList",12001,"getWifiList:system not support");
+ let err = new WifiFailImpl(getErrcode(12001));
option.fail?.(err)
option.complete?.(err)
}
@@ -181,11 +182,11 @@ export const getWifiList: GetWifiList = function (option: WifiOption) {
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
*/
-export const onGetWifiList: OnGetWifiList = function (callback: UniWifiCallback) {
-
+export const onGetWifiList: OnGetWifiList = function (callback: UniGetWifiListCallback) {
+
}
-/*
+/*
* 注销获取wifi列表的回调
*/
export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallback) {
@@ -193,12 +194,12 @@ export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallbac
}
-/*
+/*
* 获取当前连接的wifi信息
*/
export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
- let err = new UniError("uni-getConnectedWifi",12000,"getConnectedWifi:not init");
+ let err = new WifiFailImpl(getErrcode(12000));
option.fail?.(err)
option.complete?.(err)
} else{
@@ -207,7 +208,7 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected
if (success == true) {
fetchConnectedWifiWithLocationPromise(option)
}else {
- let err = new UniError("uni-getConnectedWifi",12007,"getConnectedWifi:user denied");
+ let err = new WifiFailImpl(getErrcode(12007));
option.fail?.(err)
option.complete?.(err)
}
@@ -218,50 +219,50 @@ export const getConnectedWifi: GetConnectedWifi = function (option: GetConnected
}
}
-/*
+/*
* 连接wifi
*/
export const connectWifi: ConnectWifi = function (option: WifiConnectOption) {
-
- let err = new UniError("uni-connectWifi",12001,"connectWifi:system not support");
+
+ let err = new WifiFailImpl(getErrcode(12001));
option.fail?.(err)
option.complete?.(err)
}
-/*
+/*
* 连上wifi事件的监听函数
*/
-export const onWifiConnected: OnWifiConnected = function (callback: UniWifiCallback) {
-
+export const onWifiConnected: OnWifiConnected = function (callback: UniWifiResultCallback) {
+
}
-/*
+/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
-export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifiCallback) {
-
+export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifiResultCallbackWithPartialInfo) {
+
}
-/*
+/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export const offWifiConnected: OffWifiConnected = function (callback: UniWifiCallback | null) {
}
-/*
+/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
-export const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInfo = function (callback: UniWifiCallback | null) {
+export const offWifiConnectedWithPartialInfo: OffWifiConnectedWithPartialInfo = function (callback: UniWifiResultCallbackWithPartialInfo | null) {
}
-/*
+/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
export const setWifiList: SetWifiList = function (option: WifiOption) {
- let err = new UniError("uni-setWifiList",12001,"setWifiList:system not support");
+ let err = new WifiFailImpl(getErrcode(12001));
option.fail?.(err)
option.complete?.(err)
-}
\ No newline at end of file
+}
diff --git a/uni_modules/uni-wifi/utssdk/index.d.ts b/uni_modules/uni-wifi/utssdk/index.d.ts
new file mode 100644
index 0000000000000000000000000000000000000000..64f08293f7e94642d83f3e04c2fb08997966d773
--- /dev/null
+++ b/uni_modules/uni-wifi/utssdk/index.d.ts
@@ -0,0 +1,388 @@
+declare namespace UniNamespace {
+
+ type UniWifiComplete = any
+ type WifiSuccessCallback = (res : UniWifiResult) => void
+ type WifiFailCallback = (err : UniWifiFail) => void
+ type WifiCompleteCallback = (res : UniWifiComplete) => void
+ type UniWifiCallback = () => void
+
+
+ type WifiErrorCode = 1300002
+
+ interface UniWifiInfo {
+ SSID : string;
+ BSSID ?: string;
+ secure ?: boolean;
+ signalStrength ?: number;
+ frequency ?: number;
+ }
+
+ interface UniWifiResult {
+ errCode : number,
+ errSubject : string,
+ errMsg : string,
+ wifi : UniWifiInfo | null
+ }
+
+ interface UniWifiFail {
+ errCode : WifiErrorCode
+ }
+
+ interface WifiConnectOption {
+ SSID : string | null;
+ BSSID : string | null;
+ password : string | null;
+ maunal : boolean | null;
+ partialInfo : boolean | null; //ios不生效
+ success : WifiSuccessCallback | null;
+ fail : WifiFailCallback | null;
+ complete : WifiCompleteCallback | null;
+ }
+
+ interface GetConnectedWifiOptions {
+ partialInfo : boolean | null;
+ success : WifiSuccessCallback | null;
+ fail : WifiFailCallback | null;
+ complete ?: WifiCompleteCallback | null;
+ }
+
+
+ interface WifiOption {
+ success : WifiSuccessCallback | null,
+ fail : WifiFailCallback | null,
+ complete : InstallApkCompleteCallback | null
+ }
+
+ interface UniWifiInfoWithPartialInfo {
+ SSID : string;
+ }
+
+ type UniGetWifiListCallback = (wifiInfo:UTSJSONObject) => void
+
+ type UniWifiResultCallback = (wifiInfo:UniWifiResult) => void
+
+ type UniWifiResultCallbackWithPartialInfo = (wifiInfo:UniWifiInfoWithPartialInfo) => void
+
+}
+
+declare interface Uni {
+
+ /**
+ * 初始化Wi-Fi模块
+ *
+ * @param {WifiOption} option
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { after: 'stopWifi' }
+ */
+ startWifi(option : UniNamespace.WifiOption): void,
+
+ /**
+ * 关闭 Wi-Fi 模块
+ *
+ * @param {WifiOption} option
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { before: 'startWifi' }
+ */
+ stopWifi(option : UniNamespace.WifiOption) : void,
+ /**
+ * @param {WifiConnectOption} option
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": ">=4.4 && <10.0",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest {
+ generated: false,
+ pollution: false,
+ cases:[
+ {
+ before: 'startWifi',
+ after: 'stopWifi',
+ input: [{
+ maunal:false,
+ SSID:"Xiaomi_20D0",
+ password:"streamApp!2016",
+ }],
+ output:{
+ callbackType: 'success',
+ value: { errCode: 12013 ,errMsg: "connectWifi:wifi config may be expired",errSubject: "uni-connectWifi"}
+ }
+ }
+ ]
+ }
+ */
+ connectWifi(option : UniNamespace.WifiConnectOption) : void,
+ /**
+ * 请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
+ * @param {WifiOption} option
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { before: 'startWifi', after: 'stopWifi' }
+ */
+ getWifiList(option : UniNamespace.WifiOption) : void,
+ /**
+ * 监听获取到 Wi-Fi 列表数据事件。
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ * @autotest {
+ generated: false,
+ pollution: false,
+ expectCallback: true,
+ before: 'startWifi',
+ after: 'onGetWifiListAfter',
+ cases: [
+ {
+ output: {
+ value: 0,
+ returnKey: '.wifiList.length',
+ jestExpectSyntax: 'toBeGreaterThan'
+ },
+ }
+ ]
+ }
+ */
+ onGetWifiList(callback : UniNamespace.UniGetWifiListCallback) : void,
+ /**
+ * 移除获取到 Wi-Fi 列表数据事件的监听函数。
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ offGetWifiList(callback : UniNamespace.UniWifiCallback) : void,
+ /**
+ * 获取已连接的 Wi-Fi 信息
+ *
+ * @param {GetConnectedWifiOptions} option
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { before: 'startWifi', after: 'stopWifi' }
+ */
+ getConnectedWifi(option : UniNamespace.GetConnectedWifiOptions) : void,
+ /**
+ * 监听连接上 Wi-Fi 的事件
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ onWifiConnected(callback : UniNamespace.UniWifiResultCallback) : void,
+ /**
+ * 监听连接上 Wi-Fi 的事件。
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ onWifiConnectedWithPartialInfo(callback : UniNamespace.UniWifiResultCallbackWithPartialInfo) : void,
+ /**
+ * 移除连接上 Wi-Fi 的事件的监听函数。
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "4.4.4",
+ * "uniVer": "3.7.0",
+ * "unixVer": "3.9.0"
+ * },
+ * "ios": {
+ * "osVer": "9.0",
+ * "uniVer": "3.7.7",
+ * "unixVer": "3.9.0"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ offWifiConnected(callback ?: UniNamespace.UniWifiCallback) : void,
+
+ /**
+ * 移除连接上 Wi-Fi 的事件的监听函数。
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "x",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * },
+ * "ios": {
+ * "osVer": "x",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ * @uniVersion 3.7.7
+ * @uniVueVersion 2,3 //支持的vue版本
+ * @autotest { expectCallback: true }
+ */
+ offWifiConnectedWithPartialInfo(callback ?: UniNamespace.UniWifiResultCallbackWithPartialInfo) : void,
+ /**
+ * SetWifiList 暂未实现
+ *
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "x",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * },
+ * "ios": {
+ * "osVer": "x",
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+ setWifiList(option : UniNamespace.WifiOption) : void,
+
+
+}
diff --git a/uni_modules/uni-wifi/utssdk/interface.uts b/uni_modules/uni-wifi/utssdk/interface.uts
index 14cdbf0f704f04044bc195e35a9efb2af80e62bb..db0ba89fcad6fe4e8a3a965b569347c5f41a9a59 100644
--- a/uni_modules/uni-wifi/utssdk/interface.uts
+++ b/uni_modules/uni-wifi/utssdk/interface.uts
@@ -8,7 +8,7 @@ export type WifiOption = {
};
/**
- * Wifi 链接参数封装
+ * Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID ?: string;
@@ -31,7 +31,7 @@ export type GetConnectedWifiOptions = {
complete ?: (res : any) => void
}
-/*
+/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
@@ -42,6 +42,10 @@ export type UniWifiInfo = {
frequency ?: number;
}
+export type UniWifiInfoWithPartialInfo = {
+ SSID : string;
+}
+
export type UniWifiResult = {
errCode : number,
@@ -52,6 +56,12 @@ export type UniWifiResult = {
export type UniWifiCallback = () => void
+export type UniGetWifiListCallback = (wifiInfo:UTSJSONObject) => void
+
+export type UniWifiResultCallback = (wifiInfo:UniWifiResult) => void
+
+export type UniWifiResultCallbackWithPartialInfo = (wifiInfo:UniWifiInfoWithPartialInfo) => void
+
export type StartWifi = (option : WifiOption) => void
@@ -59,7 +69,7 @@ export type StopWifi = (option : WifiOption) => void
export type GetWifiList = (option : WifiOption) => void
-export type OnGetWifiList = (callback : UniWifiCallback) => void
+export type OnGetWifiList = (callback : UniGetWifiListCallback) => void
export type OffGetWifiList = (callback : UniWifiCallback) => void
@@ -67,21 +77,40 @@ export type GetConnectedWifi = (option : GetConnectedWifiOptions) => void
export type ConnectWifi = (option : WifiConnectOption) => void
-export type OnWifiConnected = (callback : UniWifiCallback) => void
+export type OnWifiConnected = (callback : UniWifiResultCallback) => void
-export type OnWifiConnectedWithPartialInfo = (callback : UniWifiCallback) => void
+export type OnWifiConnectedWithPartialInfo = (callback : UniWifiResultCallbackWithPartialInfo) => void
export type OffWifiConnected = (callback : UniWifiCallback | null) => void
-export type OnOffWifiConnectedWithPartialInfo = (callback : UniWifiCallback | null) => void
+export type OffWifiConnectedWithPartialInfo = (callback : UniWifiResultCallbackWithPartialInfo | null) => void
export type SetWifiList = (option : WifiOption) => void
+
+/**
+ * 错误码
+ * - 12000 尚未初始化
+ * - 12001 当前系统不支持相关能力
+ * - 12002 密码错误
+ * - 12005 Android 特有,未打开 Wi-Fi 开关
+ * - 12007 用户拒绝授权链接 Wi-Fi
+ * - 12010 系统其他错误
+ * - 12013 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
+ */
+export type WifiErrorCode = 12000 |12001 | 12002 | 12005 | 12007 | 12010 | 12013;
+
+export interface WifiFail extends IUniError{
+ errCode: WifiErrorCode
+};
+
+
+
interface Uni {
/**
* 初始化Wi-Fi模块
- *
- * @param {WifiOption} option
+ *
+ * @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi
* @uniPlatform {
* "app": {
@@ -93,7 +122,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -104,20 +133,20 @@ interface Uni {
startWifi(option : WifiOption): void,
/**
* 关闭 Wi-Fi 模块
- *
- * @param {WifiOption} option
+ *
+ * @param {WifiOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi
* @uniPlatform {
* "app": {
* "android": {
* "osVer": "4.4.4",
* "uniVer": "3.7.0",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* },
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -127,7 +156,7 @@ interface Uni {
*/
stopWifi(option : WifiOption) : void,
/**
- * @param {WifiConnectOption} option
+ * @param {WifiConnectOption} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi
* @uniPlatform {
* "app": {
@@ -139,7 +168,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -180,7 +209,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -191,8 +220,8 @@ interface Uni {
getWifiList(option : WifiOption) : void,
/**
* 监听获取到 Wi-Fi 列表数据事件。
- *
- * @param {UniWifiCallback} callback
+ *
+ * @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList
* @uniPlatform {
* "app": {
@@ -204,7 +233,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -228,11 +257,11 @@ interface Uni {
]
}
*/
- onGetWifiList(callback : UniWifiCallback) : void,
+ onGetWifiList(callback : UniGetWifiListCallback) : void,
/**
* 移除获取到 Wi-Fi 列表数据事件的监听函数。
- *
- * @param {UniWifiCallback} callback
+ *
+ * @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList
* @uniPlatform {
* "app": {
@@ -244,7 +273,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -255,8 +284,8 @@ interface Uni {
offGetWifiList(callback : UniWifiCallback) : void,
/**
* 获取已连接的 Wi-Fi 信息
- *
- * @param {GetConnectedWifiOptions} option
+ *
+ * @param {GetConnectedWifiOptions} option
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#getConnectedWifi
* @uniPlatform {
* "app": {
@@ -268,7 +297,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -279,8 +308,8 @@ interface Uni {
getConnectedWifi(option : GetConnectedWifiOptions) : void,
/**
* 监听连接上 Wi-Fi 的事件
- *
- * @param {UniWifiCallback} callback
+ *
+ * @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected
* @uniPlatform {
* "app": {
@@ -292,7 +321,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -300,11 +329,11 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
- onWifiConnected(callback : UniWifiCallback) : void,
+ onWifiConnected(callback : UniWifiResultCallback) : void,
/**
* 监听连接上 Wi-Fi 的事件。
- *
- * @param {UniWifiCallback} callback
+ *
+ * @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
@@ -316,7 +345,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -324,11 +353,11 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
- onWifiConnectedWithPartialInfo(callback : UniWifiCallback) : void,
+ onWifiConnectedWithPartialInfo(callback : UniWifiResultCallbackWithPartialInfo) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
- *
- * @param {UniWifiCallback} callback
+ *
+ * @param {UniWifiCallback} callback
* @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected
* @uniPlatform {
* "app": {
@@ -340,7 +369,7 @@ interface Uni {
* "ios": {
* "osVer": "9.0",
* "uniVer": "3.7.7",
- * "unixVer": "3.9.0"
+ * "unixVer": "x"
* }
* }
* }
@@ -351,9 +380,9 @@ interface Uni {
offWifiConnected(callback : UniWifiCallback | null) : void,
/**
* 移除连接上 Wi-Fi 的事件的监听函数。
- *
- * @param {UniWifiCallback} callback
- * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#onOffWifiConnectedWithPartialInfo
+ *
+ * @param {UniWifiCallback} callback
+ * @tutorial https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo
* @uniPlatform {
* "app": {
* "android": {
@@ -372,10 +401,10 @@ interface Uni {
* @uniVueVersion 2,3 //支持的vue版本
* @autotest { expectCallback: true }
*/
- onOffWifiConnectedWithPartialInfo(callback : UniWifiCallback | null) : void,
+ offWifiConnectedWithPartialInfo(callback : UniWifiResultCallbackWithPartialInfo | null) : void,
/**
* SetWifiList 暂未实现
- *
+ *
* @uniPlatform {
* "app": {
* "android": {
@@ -392,4 +421,4 @@ interface Uni {
* }
*/
setWifiList(option : WifiOption) : void,
-}
\ No newline at end of file
+}
diff --git a/uni_modules/uni-wifi/utssdk/unierror.uts b/uni_modules/uni-wifi/utssdk/unierror.uts
new file mode 100644
index 0000000000000000000000000000000000000000..023c2de9ae886b844051c8e247ac225e7cfe939e
--- /dev/null
+++ b/uni_modules/uni-wifi/utssdk/unierror.uts
@@ -0,0 +1,59 @@
+import { WifiErrorCode, WifiFail} from "./interface.uts"
+
+/**
+ * 错误主题
+ */
+export const UniErrorSubject = 'uni-wifi';
+/**
+ * 错误码
+ * @UniError
+ */
+export const WifiUniErrors : Map = new Map([
+
+ /**
+ * 未先调用 startWifi 接口
+ */
+ [12000, 'not init.'],
+ /**
+ * 当前系统不支持相关能力
+ */
+ [12001, 'system not support'],
+ /**
+ * 密码错误
+ */
+ [12002, 'password error Wi-Fi'],
+ /**
+ * Android 特有,未打开 Wi-Fi 开关
+ */
+ [12005, 'wifi not turned on'],
+ /**
+ * 用户拒绝授权链接 Wi-Fi
+ */
+ [12007, 'user denied'],
+ /**
+ * 系统其他错误,需要在 errmsg 打印具体的错误原因
+ */
+ [12010, 'unknown error'],
+ /**
+ * 系统保存的 Wi-Fi 配置过期,建议忘记 Wi-Fi 后重试,仅 Android 支持
+ */
+ [12013, 'wifi config may be expired'],
+
+]);
+
+
+export function getErrcode(errCode : number) : WifiErrorCode {
+ const res = WifiUniErrors[errCode];
+ return res == null ? 12000 : errCode;
+}
+
+
+export class WifiFailImpl extends UniError implements WifiFail {
+ constructor(errCode : WifiErrorCode) {
+ super();
+ this.errSubject = UniErrorSubject;
+ this.errCode = errCode;
+ this.errMsg = WifiUniErrors[errCode] ?? "";
+ }
+}
+
diff --git a/uni_modules/uts-progressNotification/changelog.md b/uni_modules/uts-progressNotification/changelog.md
new file mode 100644
index 0000000000000000000000000000000000000000..332470475bb5475b7d3b24b633c91917f4dce414
--- /dev/null
+++ b/uni_modules/uts-progressNotification/changelog.md
@@ -0,0 +1,18 @@
+## 1.0.7(2023-12-11)
+去除无用代码
+## 1.0.6(2023-12-11)
+修改文档
+## 1.0.5(2023-12-11)
+1.修改插件名称
+2.修改插件引入方式为import导入
+## 1.0.4(2023-11-30)
+1. createNotificationProgress增加`onClick`回调
+2.修复在小米部分系统上,通知消息会归类于不重要通知的bug
+## 1.0.3(2023-11-28)
+更新截图
+## 1.0.2(2023-11-28)
+修改资源的包名
+## 1.0.1(2023-11-28)
+更新文档
+## 1.0.0(2023-11-28)
+Android通知栏显示进度插件
diff --git a/uni_modules/uts-progressNotification/package.json b/uni_modules/uts-progressNotification/package.json
new file mode 100644
index 0000000000000000000000000000000000000000..09e670999813e2e6271cbfd74dfbcbd43fe344a5
--- /dev/null
+++ b/uni_modules/uts-progressNotification/package.json
@@ -0,0 +1,83 @@
+{
+ "id": "uts-progressNotification",
+ "displayName": "uts-progressNotification",
+ "version": "1.0.7",
+ "description": "uts-progressNotification",
+ "keywords": [
+ "uts-progressNotification"
+],
+ "repository": "",
+ "engines": {
+ "HBuilderX": "^3.91"
+ },
+ "dcloudext": {
+ "type": "uts",
+ "sale": {
+ "regular": {
+ "price": "0.00"
+ },
+ "sourcecode": {
+ "price": "0.00"
+ }
+ },
+ "contact": {
+ "qq": ""
+ },
+ "declaration": {
+ "ads": "无",
+ "data": "插件不采集任何数据",
+ "permissions": "TargetSDKVersion33以上时需配置\n`android.permission.POST_NOTIFICATIONS`"
+ },
+ "npmurl": ""
+ },
+ "uni_modules": {
+ "dependencies": [],
+ "encrypt": [],
+ "platforms": {
+ "cloud": {
+ "tcb": "y",
+ "aliyun": "y"
+ },
+ "client": {
+ "Vue": {
+ "vue2": "y",
+ "vue3": "y"
+ },
+ "App": {
+ "app-android": {
+ "minVersion": "19"
+ },
+ "app-ios": "n"
+ },
+ "H5-mobile": {
+ "Safari": "n",
+ "Android Browser": "n",
+ "微信浏览器(Android)": "n",
+ "QQ浏览器(Android)": "n"
+ },
+ "H5-pc": {
+ "Chrome": "n",
+ "IE": "n",
+ "Edge": "n",
+ "Firefox": "n",
+ "Safari": "n"
+ },
+ "小程序": {
+ "微信": "n",
+ "阿里": "n",
+ "百度": "n",
+ "字节跳动": "n",
+ "QQ": "n",
+ "钉钉": "n",
+ "快手": "n",
+ "飞书": "n",
+ "京东": "n"
+ },
+ "快应用": {
+ "华为": "n",
+ "联盟": "n"
+ }
+ }
+ }
+ }
+}
diff --git a/uni_modules/uts-progressNotification/readme.md b/uni_modules/uts-progressNotification/readme.md
new file mode 100644
index 0000000000000000000000000000000000000000..87d85766d7694c927555da282bc1bef7d6d3a7d3
--- /dev/null
+++ b/uni_modules/uts-progressNotification/readme.md
@@ -0,0 +1,71 @@
+# uts-progressNotification
+
+## 使用说明
+
+Android平台创建显示进度的通知栏消息
+
+**注意: 需要自定义基座,否则点击通知栏消息不会拉起应用**
+
+### 导入
+
+需要import导入插件
+
+### createNotificationProgress(options : CreateNotificationProgressOptions) : void,
+
+创建显示进度的通知栏消息
+
+参数说明
+
+```
+export type CreateNotificationProgressOptions = {
+ /**
+ * 通知标题
+ * @defaultValue 应用名称
+ */
+ title ?: string | null
+ /**
+ * 通知内容
+ */
+ content : string,
+ /**
+ * 进度
+ */
+ progress : number,
+ /**
+ * 点击通知消息回调
+ * @defaultValue null
+ */
+ onClick? : (() => void) | null
+}
+```
+
+### finishNotificationProgress(options: FinishNotificationProgressOptions) : void
+
+完成时调用的API,比如下载完成后需要显示下载完成并隐藏进度时调用。
+
+参数说明
+
+
+```
+export type FinishNotificationProgressOptions = {
+ /**
+ * 通知标题
+ * @defaultValue 应用名称
+ */
+ title ?: string | null
+ /**
+ * 通知内容
+ */
+ content : string,
+ /**
+ * 点击通知消息回调
+ */
+ onClick : () => void
+}
+```
+
+
+### cancelNotificationProgress() : void
+
+取消通知消息显示
+
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/AndroidManifest.xml b/uni_modules/uts-progressNotification/utssdk/app-android/AndroidManifest.xml
new file mode 100644
index 0000000000000000000000000000000000000000..93749e96d581dd4446cf670d9406ba4c01291021
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/AndroidManifest.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts b/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts
new file mode 100644
index 0000000000000000000000000000000000000000..283e01db3035765dd294f3f40e0d9f52e037da08
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/TransparentActivity.uts
@@ -0,0 +1,61 @@
+import Activity from "android.app.Activity";
+import Bundle from 'android.os.Bundle';
+import Build from 'android.os.Build';
+import View from 'android.view.View';
+import Color from 'android.graphics.Color';
+import WindowManager from 'android.view.WindowManager';
+import { globalNotificationProgressFinishCallBack, globalNotificationProgressCallBack } from './index.uts';
+import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
+
+
+export class TransparentActivity extends Activity {
+ constructor() {
+ super()
+ }
+
+ override onCreate(savedInstanceState : Bundle | null) {
+ super.onCreate(savedInstanceState)
+ this.fullScreen(this)
+ const action = this.getIntent().getAction()
+ if (action == ACTION_DOWNLOAD_FINISH) {
+ setTimeout(() => {
+ globalNotificationProgressFinishCallBack()
+ globalNotificationProgressFinishCallBack = () => { }
+ }, 100)
+ this.overridePendingTransition(0, 0)
+ }
+
+ if (action == ACTION_DOWNLOAD_PROGRESS) {
+ setTimeout(() => {
+ globalNotificationProgressCallBack?.()
+ globalNotificationProgressCallBack = () => { }
+ }, 100)
+ this.overridePendingTransition(0, 0)
+ }
+
+ setTimeout(() => {
+ this.finish()
+ }, 20)
+ }
+
+
+ @Suppress("DEPRECATION")
+ private fullScreen(activity : Activity) {
+ if (Build.VERSION.SDK_INT >= 19) {
+ if (Build.VERSION.SDK_INT >= 21) {
+ const window = activity.getWindow();
+ const decorView = window.getDecorView();
+ const option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
+ decorView.setSystemUiVisibility(option);
+ window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+ window.setStatusBarColor(Color.TRANSPARENT);
+ } else {
+ const window = activity.getWindow();
+ const attributes = window.getAttributes();
+ const flagTranslucentStatus = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
+ attributes.flags |= flagTranslucentStatus;
+ window.setAttributes(attributes);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/config.json b/uni_modules/uts-progressNotification/utssdk/app-android/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..7deedfa4f1562e221ea6b8bb3e828485447e2f5f
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/config.json
@@ -0,0 +1,3 @@
+{
+ "minSdkVersion": "19"
+}
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/constant.uts b/uni_modules/uts-progressNotification/utssdk/app-android/constant.uts
new file mode 100644
index 0000000000000000000000000000000000000000..8652ac4be355ac4726516da9a46d99bcd86ce1a5
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/constant.uts
@@ -0,0 +1,2 @@
+export const ACTION_DOWNLOAD_FINISH = "ACTION_DOWNLOAD_FINISH"
+export const ACTION_DOWNLOAD_PROGRESS = "ACTION_DOWNLOAD_PROGRESS"
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/index.uts b/uni_modules/uts-progressNotification/utssdk/app-android/index.uts
new file mode 100644
index 0000000000000000000000000000000000000000..39d14cd58fb17e0adf913bbd6995e5849345e313
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/index.uts
@@ -0,0 +1,159 @@
+import Build from 'android.os.Build';
+import Context from 'android.content.Context';
+import NotificationManager from 'android.app.NotificationManager';
+import NotificationChannel from 'android.app.NotificationChannel';
+import Notification from 'android.app.Notification';
+import Intent from 'android.content.Intent';
+import ComponentName from 'android.content.ComponentName';
+import PendingIntent from 'android.app.PendingIntent';
+import { CreateNotificationProgressOptions, FinishNotificationProgressOptions } from '../interface.uts';
+import { ACTION_DOWNLOAD_FINISH, ACTION_DOWNLOAD_PROGRESS } from "./constant.uts"
+
+
+export { TransparentActivity } from './TransparentActivity.uts';
+
+
+const DOWNLOAD_PROGRESS_NOTIFICATION_ID : Int = 7890
+const DC_DOWNLOAD_CHANNEL_ID = "下载文件"
+const DC_DOWNLOAD_CHANNEL_NAME = "用于显示现在进度的渠道"
+
+
+let notificationBuilder : Notification.Builder | null = null
+
+let timeId = -1
+
+let histroyProgress = 0
+
+let isProgress = false
+
+export let globalNotificationProgressCallBack : (() => void) | null = () => { }
+export let globalNotificationProgressFinishCallBack = () => { }
+
+export function createNotificationProgress(options : CreateNotificationProgressOptions) : void {
+ const { content, progress, onClick } = options
+
+ if (progress == 100) {
+ clearTimeout(timeId)
+ const context = UTSAndroid.getAppContext() as Context
+ realCreateNotificationProgress(options.title ?? getAppName(context), content, progress, onClick)
+ reset()
+ return
+ }
+
+ histroyProgress = progress
+ if (timeId != -1) {
+ return
+ }
+
+ const context = UTSAndroid.getAppContext() as Context
+ if (!isProgress) {
+ realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
+ isProgress = true
+ } else {
+ timeId = setTimeout(() => {
+ realCreateNotificationProgress(options.title ?? getAppName(context), content, histroyProgress, onClick)
+ timeId = -1
+ }, 1000)
+ }
+}
+
+
+export function cancelNotificationProgress() : void {
+ const context = UTSAndroid.getAppContext() as Context
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ notificationManager.cancel(DOWNLOAD_PROGRESS_NOTIFICATION_ID)
+ reset()
+}
+
+
+function realCreateNotificationProgress(title : string, content : string, progress : number, cb : (() => void) | null) : void {
+ globalNotificationProgressCallBack = cb
+ const context = UTSAndroid.getAppContext() as Context
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ createDownloadChannel(notificationManager)
+ const builder = createNotificationBuilder(context)
+ builder.setProgress(100, progress.toInt(), false)
+ builder.setContentTitle(title)
+ builder.setContentText(content)
+ builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_PROGRESS));
+ notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
+}
+
+
+export function finishNotificationProgress(options : FinishNotificationProgressOptions) {
+ globalNotificationProgressFinishCallBack = options.onClick
+ const context = UTSAndroid.getAppContext() as Context
+ const notificationManager = context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
+ createDownloadChannel(notificationManager)
+ const builder = createNotificationBuilder(context)
+ builder.setProgress(0, 0, false)
+ builder.setContentTitle(options.title ?? getAppName(context))
+ builder.setContentText(options.content)
+ //小米rom setOngoing未false的时候,会被通知管理器归为不重要通知
+ // builder.setOngoing(false)
+ builder.setAutoCancel(true);
+ builder.setContentIntent(createPendingIntent(context, ACTION_DOWNLOAD_FINISH));
+ notificationManager.notify(DOWNLOAD_PROGRESS_NOTIFICATION_ID, builder.build())
+ reset()
+}
+
+function reset() {
+ isProgress = false
+ notificationBuilder = null
+ histroyProgress = 0
+ if (timeId != -1) {
+ clearTimeout(timeId)
+ timeId = -1
+ }
+}
+
+
+
+function createPendingIntent(context : Context, action : string) : PendingIntent {
+ const i = new Intent(action);
+ i.setComponent(new ComponentName(context.getPackageName(), "uts.sdk.modules.utsProgressNotification.TransparentActivity"));
+ let flags = PendingIntent.FLAG_ONE_SHOT;
+ if (Build.VERSION.SDK_INT >= 23) {
+ flags = PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE;
+ }
+ return PendingIntent.getActivity(context, DOWNLOAD_PROGRESS_NOTIFICATION_ID, i, flags);
+}
+
+
+function createDownloadChannel(notificationManager : NotificationManager) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ const channel = new NotificationChannel(
+ DC_DOWNLOAD_CHANNEL_ID,
+ DC_DOWNLOAD_CHANNEL_NAME,
+ NotificationManager.IMPORTANCE_LOW
+ )
+ notificationManager.createNotificationChannel(channel)
+ }
+}
+@Suppress("DEPRECATION")
+function createNotificationBuilder(context : Context) : Notification.Builder {
+ if (notificationBuilder == null) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ notificationBuilder = new Notification.Builder(context, DC_DOWNLOAD_CHANNEL_ID)
+ } else {
+ notificationBuilder = new Notification.Builder(context)
+ }
+ notificationBuilder!.setSmallIcon(context.getApplicationInfo().icon)
+ notificationBuilder!.setOngoing(true)
+ notificationBuilder!.setSound(null)
+ }
+ return notificationBuilder!
+}
+
+@Suppress("DEPRECATION")
+function getAppName(context : Context) : string {
+ let appName = ""
+ try {
+ const packageManager = context.getPackageManager()
+ const applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0)
+ appName = packageManager.getApplicationLabel(applicationInfo) as string
+ } catch (e : Exception) {
+ e.printStackTrace()
+ }
+ return appName
+}
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-android/res/values/notification_progress_styles.xml b/uni_modules/uts-progressNotification/utssdk/app-android/res/values/notification_progress_styles.xml
new file mode 100644
index 0000000000000000000000000000000000000000..cc01105b78513e66c7e1086ffe5ff564c71ae34f
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-android/res/values/notification_progress_styles.xml
@@ -0,0 +1,11 @@
+
+
+
+
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-ios/config.json b/uni_modules/uts-progressNotification/utssdk/app-ios/config.json
new file mode 100644
index 0000000000000000000000000000000000000000..d6281248a698f70985f2fd54722b527135d860d6
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-ios/config.json
@@ -0,0 +1,3 @@
+{
+ "deploymentTarget": "9"
+}
\ No newline at end of file
diff --git a/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts b/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts
new file mode 100644
index 0000000000000000000000000000000000000000..e45e1e4d3ea5281d36178987e4edaa428cd6ce15
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/app-ios/index.uts
@@ -0,0 +1,85 @@
+/**
+ * 引用 iOS 系统库,示例如下:
+ * import { UIDevice } from "UIKit";
+ * [可选实现,按需引入]
+ */
+
+/* 引入 interface.uts 文件中定义的变量 */
+import { MyApiOptions, MyApiResult, MyApi, MyApiSync } from '../interface.uts';
+
+/* 引入 unierror.uts 文件中定义的变量 */
+import { MyApiFailImpl } from '../unierror';
+
+/**
+ * 引入三方库
+ * [可选实现,按需引入]
+ *
+ * 在 iOS 平台引入三方库有以下两种方式:
+ * 1、通过引入三方库framework 或者.a 等方式,需要将 .framework 放到 ./Frameworks 目录下,将.a 放到 ./Libs 目录下。更多信息[详见](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html#ios-平台原生配置)
+ * 2、通过 cocoaPods 方式引入,将要引入的 pod 信息配置到 config.json 文件下的 dependencies-pods 字段下。详细配置方式[详见](https://uniapp.dcloud.net.cn/plugin/uts-ios-cocoapods.html)
+ *
+ * 在通过上述任意方式依赖三方库后,使用时需要在文件中 import:
+ * 示例:import { LottieLoopMode } from 'Lottie'
+ */
+
+/**
+ * UTSiOS 为平台内置对象,不需要 import 可直接调用其API,[详见](https://uniapp.dcloud.net.cn/uts/utsios.html)
+ */
+
+/**
+ * 异步方法
+ *
+ * uni-app项目中(vue/nvue)调用示例:
+ * 1、引入方法声明 import { myApi } from "@/uni_modules/uts-api"
+ * 2、方法调用
+ * myApi({
+ * paramA: false,
+ * complete: (res) => {
+ * console.log(res)
+ * }
+ * });
+ *
+ */
+export const myApi : MyApi = function (options : MyApiOptions) {
+
+ if (options.paramA == true) {
+ // 返回数据
+ const res : MyApiResult = {
+ fieldA: 85,
+ fieldB: true,
+ fieldC: 'some message'
+ };
+ options.success?.(res);
+ options.complete?.(res);
+
+ } else {
+ // 返回错误
+ let failResult = new MyApiFailImpl(9010001);
+ options.fail?.(failResult)
+ options.complete?.(failResult)
+ }
+
+}
+
+/**
+ * 同步方法
+ *
+ * uni-app项目中(vue/nvue)调用示例:
+ * 1、引入方法声明 import { myApiSync } from "@/uni_modules/uts-api"
+ * 2、方法调用
+ * myApiSync(true);
+ *
+ */
+export const myApiSync : MyApiSync = function (paramA : boolean) : MyApiResult {
+ // 返回数据,根据插件功能获取实际的返回值
+ const res : MyApiResult = {
+ fieldA: 85,
+ fieldB: paramA,
+ fieldC: 'some message'
+ };
+ return res;
+}
+
+/**
+ * 更多插件开发的信息详见:https://uniapp.dcloud.net.cn/plugin/uts-plugin.html
+ */
diff --git a/uni_modules/uts-progressNotification/utssdk/interface.uts b/uni_modules/uts-progressNotification/utssdk/interface.uts
new file mode 100644
index 0000000000000000000000000000000000000000..957035338481eed25cc286e7032bc4abd1ec6319
--- /dev/null
+++ b/uni_modules/uts-progressNotification/utssdk/interface.uts
@@ -0,0 +1,46 @@
+export type CreateNotificationProgressOptions = {
+ /**
+ * 通知标题
+ * @defaultValue 应用名称
+ */
+ title ?: string | null
+ /**
+ * 通知内容
+ */
+ content : string,
+ /**
+ * 进度
+ */
+ progress : number,
+ /**
+ * 点击通知消息回调
+ * @defaultValue null
+ */
+ onClick? : (() => void) | null
+}
+
+
+export type FinishNotificationProgressOptions = {
+ /**
+ * 通知标题
+ * @defaultValue 应用名称
+ */
+ title ?: string | null
+ /**
+ * 通知内容
+ */
+ content : string,
+ /**
+ * 点击通知消息回调
+ */
+ onClick : () => void
+}
+
+
+export type CreateNotificationProgress = (options : CreateNotificationProgressOptions) => void;
+
+
+export type CancelNotificationProgress = () => void;
+
+
+export type FinishNotificationProgress = (options: FinishNotificationProgressOptions) => void
diff --git a/uni_modules/uts-progressNotification/utssdk/unierror.uts b/uni_modules/uts-progressNotification/utssdk/unierror.uts
new file mode 100644
index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391