diff --git a/pages/SyntaxCase/utsAndroid.vue b/pages/SyntaxCase/utsAndroid.vue
index cd86e46e0ded41c56187708e7b568aa244116b6f..7ba1af6f8584e28c1edebb0c125fb532a46e4d6f 100644
--- a/pages/SyntaxCase/utsAndroid.vue
+++ b/pages/SyntaxCase/utsAndroid.vue
@@ -14,6 +14,7 @@
+
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
@@ -27,11 +28,16 @@
{{text}}
-
+
-
+
+
+ 获取设备信息,观察是否符合预期
+
+
+
@@ -48,7 +54,9 @@
convert2AbsFullPathTest,
unRegLifecycle,
initAppLifecycle,
- gotoCameraTake
+ gotoCameraTake,
+ getDeviceInfoTest,
+ privacyStateTest
} from '@/uni_modules/uts-platform-api'
/**
@@ -70,6 +78,23 @@
});
},
methods: {
+ privacyStateClick(){
+ privacyStateTest(function(ret,desc){
+ if (ret) {
+ uni.showToast({
+ title: '测试通过'
+ })
+ } else {
+ uni.showToast({
+ icon: 'none',
+ title: '失败:' + desc
+ })
+ }
+ })
+ },
+ getDeviceInfoClick(){
+ this.text = getDeviceInfoTest()
+ },
testGoOtherActivity(){
var that = this;
let ret = gotoCameraTake(function(file){
@@ -142,7 +167,6 @@
dispatchAsyncTest(function(ret,desc){
if (ret) {
uni.showToast({
- icon: 'none',
title: '测试通过'
})
} else {
diff --git a/uni_modules/uts-platform-api/utssdk/app-android/index.uts b/uni_modules/uts-platform-api/utssdk/app-android/index.uts
index 21d0dae2b1681bb14928852740b8c004620855d3..3a922c65d84ffc86a7da651332367f8863d073ee 100644
--- a/uni_modules/uts-platform-api/utssdk/app-android/index.uts
+++ b/uni_modules/uts-platform-api/utssdk/app-android/index.uts
@@ -5,6 +5,7 @@ import MediaStore from "android.provider.MediaStore";
import Activity from "android.app.Activity";
import Bitmap from "android.graphics.Bitmap";
import FileOutputStream from "java.io.FileOutputStream";
+import File from "java.io.File";
import Intent from 'android.content.Intent';
/**
@@ -37,6 +38,30 @@ export function getUniActivityTest() : boolean {
return true
}
+
+export function privacyStateTest(callback : (ret : boolean, desc : string) => void) {
+
+ // 先重置用户同意状态
+ UTSAndroid.resetPrivacyAgree()
+
+ if (UTSAndroid.isPrivacyAgree() == true) {
+ // 重置没有生效
+ callback(false,"resetPrivacyAgree error")
+ }
+
+ UTSAndroid.setPrivacyAgree(true)
+ UTSAndroid.dispatchAsync("io",function(res){
+ if (UTSAndroid.isPrivacyAgree() == false) {
+ // 重置没有生效
+ callback(false,"setPrivacyAgree error")
+ console.log("setPrivacyAgree error")
+ }
+ callback(true,"pass")
+ },null)
+
+}
+
+
/**
* UTSAndroid.getAppTempPath 测试示例
*/
@@ -245,7 +270,7 @@ export function arrayPermissionFlowTest(callback : (ret : boolean, desc : string
let permissionNeed = utsArrayOf("android.permission.READ_CALENDAR", "android.permission.WRITE_CALENDAR", "android.permission.READ_CONTACTS", "android.permission.WRITE_CONTACTS", "android.permission.GET_ACCOUNTS")
if (UTSAndroid.getSystemPermissionDenied(UTSAndroid.getUniActivity()!, permissionNeed).isEmpty()) {
- callback(false, "预期当前不具备 读写日历/联系人的权限")
+ callback(false, "已具备 日历/联系人权限")
return;
}
@@ -273,7 +298,34 @@ export function arrayPermissionFlowTest(callback : (ret : boolean, desc : string
}
-
+/**
+ * 获取设备信息
+ */
+export function getDeviceInfoTest():string {
+ let info = ''
+ info += 'isUniMp: '+UTSAndroid.isUniMp() + "\n ";
+ info += 'getAppDarkMode: '+UTSAndroid.getAppDarkMode() + "\n ";
+ info += 'getLanguageInfo: '+UTSAndroid.getLanguageInfo(UTSAndroid.getAppContext()!!) + "\n ";
+ info += 'getWebViewInfo: '+UTSAndroid.getWebViewInfo(UTSAndroid.getAppContext()!!) + "\n ";
+ info += 'getDeviceID: '+UTSAndroid.getDeviceID(UTSAndroid.getAppContext()!!) + "\n ";
+ info += 'getOAID: '+UTSAndroid.getOAID() + "\n ";
+ info += 'getInnerVersion: '+UTSAndroid.getInnerVersion() + "\n ";
+ info += 'getUniCompileVersion: '+UTSAndroid.getUniCompileVersion() + "\n ";
+ info += 'getUniRuntimeVersion: '+UTSAndroid.getUniRuntimeVersion() + "\n ";
+ info += 'getAppId: '+UTSAndroid.getAppId() + "\n ";
+ info += 'getAppVersion: '+UTSAndroid.getAppVersion() + "\n ";
+ info += 'getAppName: '+UTSAndroid.getAppName() + "\n ";
+ info += 'getOsTheme: '+UTSAndroid.getOsTheme() + "\n ";
+ info += 'getScreenInfo: '+UTSAndroid.getScreenInfo() + "\n ";
+ info += 'getStatusBarHeight: '+UTSAndroid.getStatusBarHeight() + "\n ";
+ info += 'isTitleNViewShow: '+UTSAndroid.isTitleNViewShow() + "\n ";
+ info += 'isTabBarShow: '+UTSAndroid.isTabBarShow() + "\n ";
+ info += 'getWindowHeight: '+UTSAndroid.getWindowHeight() + "\n ";
+ info += 'getSafeAreaInsets: '+UTSAndroid.getSafeAreaInsets() + "\n ";
+ info += 'isUniAppX: '+UTSAndroid.isUniAppX() + "\n ";
+
+ return info
+}
/**
* 任务分发测试
*/
@@ -295,11 +347,11 @@ export function dispatchAsyncTest(callback : (ret : boolean, desc : string) => v
/**
* dom 参数,只在2.0生效,1.0会自动切换到main线程
*/
- if(!Thread.currentThread().name.startWith("DefaultDispatcher")){
+ if(!Thread.currentThread().name.contains("DefaultDispatcher")){
callback(false,"io thread error")
return
}
- callback(true)
+ callback(true,"pass")
},null)
},null)
diff --git a/uni_modules/uts-tests/utssdk/JSON.uts b/uni_modules/uts-tests/utssdk/JSON.uts
index 7bc2a0a4042ce7c4a4fe595656fce6497839d3cd..cd6fc11460e73c067816000b3268f2885dc3607f 100644
--- a/uni_modules/uts-tests/utssdk/JSON.uts
+++ b/uni_modules/uts-tests/utssdk/JSON.uts
@@ -1,5 +1,12 @@
import { describe, test, expect, Result } from './tests.uts'
+
+
+class User{
+ name:string = "";
+ age:number = 12;
+}
+
export function testJSON() : Result {
return describe("JSON", () => {
test('parse', () => {
@@ -19,7 +26,8 @@ export function testJSON() : Result {
age: 30,
city: 'New York',
});
-
+
+
const json2 = '{"string":"Hello","number":42,"boolean":true,"nullValue":null,"array":[1,2,3],"object":{"nestedKey":"nestedValue"}}';
const obj2 = JSON.parse(json2)!;
expect(obj2).toEqual({
@@ -35,7 +43,11 @@ export function testJSON() : Result {
expect(obj2['object']).toEqual({
nestedKey: 'nestedValue',
})
-
+
+ // 目前仅android 支持,暂不放开
+ // let obj3 = JSON.parse(json1);
+ // console.log(obj3)
+
// const json3 = '["apple","banana","cherry"]';
// const obj3 = JSON.parse(json3)!;
// TODO JSON.parse 后数组的类型 无法强转
diff --git a/uni_modules/uts-tests/utssdk/Number.uts b/uni_modules/uts-tests/utssdk/Number.uts
index c3844c3577d89159f0a5db9b25fa35a06e10afda..fbf626f34651c5fb3559999a7494a06f0cf702a5 100644
--- a/uni_modules/uts-tests/utssdk/Number.uts
+++ b/uni_modules/uts-tests/utssdk/Number.uts
@@ -11,5 +11,29 @@ export function testNumber(): Result {
expect(financial(0)).toEqual("0.00");
expect(financial(1)).toEqual("1.00");
})
+
+ test('parseInt', () => {
+ expect(parseInt("123.456")).toEqual(123);
+ })
+ test('parseFloat', () => {
+ expect(parseFloat("11.20")).toEqual(11.2);
+ })
+
+ test('isFinite', () => {
+ expect(isFinite(1000 / 1)).toEqual(true);
+ expect(isFinite(910)).toEqual(true);
+ expect(isFinite(0)).toEqual(true);
+ })
+
+ test('isNaN', () => {
+ expect(isNaN(0)).toEqual(false);
+ })
+
+ test('toPrecision', () => {
+ expect(123.456.toPrecision(4)).toEqual("123.5");
+ expect(0.004.toPrecision(4)).toEqual("0.004000");
+ expect(1.23e5.toPrecision(4)).toEqual("1.230e+5");
+ })
+
})
}