// index.uts
import Presentation from "android.app.Presentation";
import Display from "android.view.Display";
import Context from "android.content.Context";
import Bundle from "android.os.Bundle";
import R from 'io.dcloud.uni_modules.uts_sunmi_client.R';
class WebPresentation extends Presentation {
constructor(outerContext : Context, display : Display, url : string) {
super(outerContext, display)
}
override onCreate(savedInstanceState ?: Bundle) {
super.onCreate(savedInstanceState);
//自设布局
setContentView(R.layout.main_activity);
}
}
// 获取第二块屏幕
export function getPresentationDisplays() : Display | null {
const context = UTSAndroid.getAppContext();
if (context === null) {
return null
}
const mDisplayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager;
const displays = mDisplayManager.getDisplays()
const displayList = Array.fromNative(displays)
for (let i = 0; i < displayList.length; i = i + 1) {
const display = displayList[i] as Display;
console.log("屏幕" + displayList[i] as Display)
if(i==1){
return display
}
}
return null;
}
export function showTextDisplay(url : string) : IRes {
const activity = UTSAndroid.getUniActivity();
if (activity === null) {
return { code: 400, msg: 'activity is null' }
}
const presentationDisplay = getPresentationDisplays()
if (presentationDisplay != null) {
const textDisplay = new WebPresentation(activity, presentationDisplay, url);
textDisplay.show();
return { code: 0, msg: 'success' }
}
return { code: 200, msg: '没有副屏' }
}
// res/layout/main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="match_parent">
<WebView android:id="@+id/webview" android:layout_width="match_parent" android:layout_height="match_parent" />
</LinearLayout>
// index.nvue
onMounted(() => {
showTextDisplay('http://www.baidu.com')
});
j***@lvluokeji.cn (作者)
试过了在原生环境是没问题的,用uts实现就会出现这个问题,图放评论里了
2025-01-14 12:28