Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

最新版本7.0.2获取设备的宽高都为0 #1138

Open
qwe317149766 opened this issue Aug 15, 2024 · 7 comments
Open

最新版本7.0.2获取设备的宽高都为0 #1138

qwe317149766 opened this issue Aug 15, 2024 · 7 comments

Comments

@qwe317149766
Copy link

`3:24:45.470/V: 开始运行[/storage/emulated/0/脚本/fb.js]
13:24:45.477/D: params.cacheName tiktokCache
13:24:50.735/D: 0 'device.width'
13:24:50.736/D: 0 'device.height'
13:24:50.736/D: device: 0 0
13:24:50.737/D: 0 0
13:24:50.757/E: Wrapped CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.5.5) /build/master_pack-android/opencv/modules/imgproc/src/resize.cpp:4055: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'
] (/android_asset/modules/images.js#306)
Wrapped CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.5.5) /build/master_pack-android/opencv/modules/imgproc/src/resize.cpp:4055: error: (-215:Assertion failed) inv_scale_x > 0 in function 'resize'
]
at /android_asset/modules/images.js:306:0
at findImgClick (/storage/emulated/0/脚本/common.js:830:0)
at /storage/emulated/0/脚本/fb.js:6:0

@aiselp
Copy link
Contributor

aiselp commented Aug 16, 2024

打印device.width是正常的

@mouuii
Copy link

mouuii commented Sep 8, 2024

我也遇到这问题了,咋回事

@mouuii
Copy link

mouuii commented Oct 9, 2024

有人吗

@xxl-cc
Copy link

xxl-cc commented Oct 22, 2024

同样的问题,我打印出来也是0

@Yuan-ZW
Copy link

Yuan-ZW commented Oct 24, 2024

  1. Autox.js 版本:7.0.4
  2. Autox.js 下载渠道:https://github.com/kkevsekk1/AutoX/releases
  3. Android 版本:Android 13
  4. Android 机型:小米10
  5. Android 系统类别:Hyper OS

一样的问题 device.width 和 device.height 都是0

@steelywing
Copy link

Try

console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().widthPixels);
console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().heightPixels);

Relate: #1246 (comment)

@Yuan-ZW
Copy link

Yuan-ZW commented Oct 30, 2024

Try

console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().widthPixels);
console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().heightPixels);

Relate: #1246 (comment)

有用 !
不过有个问题, 这样获得的高度和原本的 device.height 之间差了一个状态栏高度

所以最后我是这样实现的:

// 获取状态栏高度 (忘了从哪抄来的了, 但是好用)
function getStatusBarHeight() {
  let result = 0
  let resId = context.getResources().getIdentifier('status_bar_height', 'dimen', 'android')
  if (resId > 0) {
    result = context.getResources().getDimensionPixelOffset(resId)
  }
  if (result <= 0) {
    result = context.getResources().getDimensionPixelOffset(R.dimen.dimen_25dp)
  }
  return result
}

// 获取屏幕宽高
function getDeviceSize() {
  let displayMetrics = Packages.android.content.res.Resources.getSystem().getDisplayMetrics()
  return {
    width: displayMetrics.widthPixels,
    height: displayMetrics.heightPixels + getStatusBarHeight(),
  }
}

let deviceSize = getDeviceSize()

console.log(deviceSize)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants