更新记录
1.0.0(2023-03-06)
监听屏幕横竖屏切换,获取当前屏幕横竖屏方向
平台兼容性
Android | Android CPU类型 | iOS |
---|---|---|
适用版本区间:4.4 - 12.0 | armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 | 适用版本区间:9 - 16 |
原生插件通用使用流程:
- 购买插件,选择该插件绑定的项目。
- 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
- 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
- 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
- 开发完毕后正式云打包
付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios
注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择
监听屏幕横竖屏切换,获取当前屏幕横竖屏方向
插件声明
var listenscreenorientation = uni.requireNativePlugin("wrs-listenscreenorientation");
- 始监听横竖屏切换
listenscreenorientation.setCallback((resp) => {
this.showMsg(JSON.stringify(resp));
var rotation = resp.rotation;
switch (uni.getSystemInfoSync().platform) {
case 'android': {
switch (rotation) {
// 竖屏
case 0:
this.showMsg("竖屏-充电口在下");
break;
// 横屏-home键在右
case 1:
this.showMsg("横屏-充电口在右");
break;
// 横屏-home键在左
case 3:
this.showMsg("横屏-充电口在左");
break;
default:
break;
}
}
break;
case 'ios': {
switch (rotation) {
// UIDeviceOrientationUnknown
case 0:
this.showMsg("方向未知");
break;
// UIDeviceOrientationPortrait
case 1:
this.showMsg("竖屏-充电口在下");
break;
// UIDeviceOrientationPortraitUpsideDown
case 2:
this.showMsg("竖屏-充电口在上");
break;
// UIDeviceOrientationLandscapeLeft
case 3:
this.showMsg("横屏-充电口在左");
break;
// UIDeviceOrientationLandscapeRight
case 4:
this.showMsg("横屏-充电口在右");
break;
// UIDeviceOrientationFaceUp,Device oriented flat, face up
case 5:
this.showMsg("Device oriented flat, face up");
break;
// UIDeviceOrientationFaceDown,Device oriented flat, face down
case 6:
this.showMsg("Device oriented flat, face down");
break;
default:
break;
}
}
break;
default:
break;
}
});
- 取消监听
listenscreenorientation.cancelCallback();
- 获取当前屏幕横竖屏方向
listentel.getCallState((resp) => {
this.showMsg(JSON.stringify(resp));
switch (uni.getSystemInfoSync().platform) {
case 'android': {
var callState = resp.callState;
var msg = "";
switch (callState) {
// CALL_STATE_IDLE
case 0:
msg = "监测到挂断电话或空闲状态"
break;
// CALL_STATE_RINGING:监测到电话呼入,来电响铃
case 1:
msg = "监测到电话呼入,来电响铃"
break;
// CALL_STATE_OFFHOOK
case 2:
msg = "接听电话"
break;
default:
break;
}
this.showMsg("当前电话状态:" + msg);
}
break;
case 'ios': {
var currentCalls = resp.currentCalls;
if (currentCalls) {
this.showMsg("当前电话状态:当前正在进行" + currentCalls.length + "个通话");
} else {
this.showMsg("当前电话状态:当前没有通话");
}
}
break;
default:
break;
}
});
- 获取当前电话状态
listenscreenorientation.getScreenOrientation((resp) => {
this.showMsg(JSON.stringify(resp));
var rotation = resp.rotation;
switch (uni.getSystemInfoSync().platform) {
case 'android': {
switch (rotation) {
// 竖屏
case 0:
this.showMsg("竖屏-充电口在下");
break;
// 横屏-home键在右
case 1:
this.showMsg("横屏-充电口在右");
break;
// 横屏-home键在左
case 3:
this.showMsg("横屏-充电口在左");
break;
default:
break;
}
}
break;
case 'ios': {
switch (rotation) {
// UIDeviceOrientationUnknown
case 0:
this.showMsg("方向未知");
break;
// UIDeviceOrientationPortrait
case 1:
this.showMsg("竖屏-充电口在下");
break;
// UIDeviceOrientationPortraitUpsideDown
case 2:
this.showMsg("竖屏-充电口在上");
break;
// UIDeviceOrientationLandscapeLeft
case 3:
this.showMsg("横屏-充电口在左");
break;
// UIDeviceOrientationLandscapeRight
case 4:
this.showMsg("横屏-充电口在右");
break;
// UIDeviceOrientationFaceUp,Device oriented flat, face up
case 5:
this.showMsg("Device oriented flat, face up");
break;
// UIDeviceOrientationFaceDown,Device oriented flat, face down
case 6:
this.showMsg("Device oriented flat, face down");
break;
default:
break;
}
}
break;
default:
break;
}
});
支持定制,联系方式 QQ:252797991