-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Comments
打印device.width是正常的 |
我也遇到这问题了,咋回事 |
有人吗 |
同样的问题,我打印出来也是0 |
一样的问题 device.width 和 device.height 都是0 |
Try console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().widthPixels);
console.log(Packages.android.content.res.Resources.getSystem().getDisplayMetrics().heightPixels); Relate: #1246 (comment) |
有用 ! 所以最后我是这样实现的: // 获取状态栏高度 (忘了从哪抄来的了, 但是好用)
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
`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
The text was updated successfully, but these errors were encountered: