HarmonyOS鸿蒙Next PC中创建悬浮窗成功,但是显示失败报错Failed to show the window. Cause: {"code":1300002}
HarmonyOS鸿蒙Next PC中创建悬浮窗成功,但是显示失败报错Failed to show the window. Cause: {“code”:1300002} 安装官方的代码,创建悬浮窗是成功的,也加载页面了,但是调用showWindow方法报错了
Failed to show the window. Cause: {“code”:1300002}
代码就是官方的代码,一模一样
let windowClass: window.Window|null = null;
// 窗口类型设置为window.WindowType.TYPE_FLOAT
let config: window.Configuration = {
name: "floatWindow", windowType: window.WindowType.TYPE_FLOAT, ctx: getContext(this)
};
// 创建悬浮窗
window.createWindow(config, (err, data) => {
if (err.code) {
console.error('Failed to create the floatWindow. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in creating the floatWindow. Data: ' + JSON.stringify(data));
windowClass = data;
// 用windowClass变量接收创建的悬浮窗
this.windowClass = data;
// 设置悬浮窗位置
windowClass.moveWindowTo(300, 300, (err) => {
if (err.code) {
console.error('Failed to move the window. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in moving the window.');
});
// 设置悬浮窗大小
windowClass.resize(500, 500, (err) => {
if (err.code) {
console.error('Failed to change the window size. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in changing the window size.');
});
// 为悬浮窗加载页面内容,这里可以设置在main_pages.json中配置的页面
windowClass.setUIContent("pages/FloatContent", (err) => {
if (err.code) {
console.error('Failed to load the content. Cause:' + JSON.stringify(err));
return;
}
console.info('Succeeded in loading the content.');
// 显示悬浮窗。
if (windowClass != null){
windowClass.showWindow((err) => {
if (err.code) {
console.error('Failed to show the window. Cause: ' + JSON.stringify(err));
return;
}
console.info('Succeeded in showing the window.');
});
}
});
});
更多关于HarmonyOS鸿蒙Next PC中创建悬浮窗成功,但是显示失败报错Failed to show the window. Cause: {"code":1300002}的实战教程也可以访问 https://www.itying.com/category-93-b0.html
4 回复
最后怎么解决的呢? 权限问题吧,普通应用无法使用Float权限。
更多关于HarmonyOS鸿蒙Next PC中创建悬浮窗成功,但是显示失败报错Failed to show the window. Cause: {"code":1300002}的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
之前就已经申请了权限,跟权限没关系,这边在创建悬浮窗口之后,要立刻将主窗口最小化,这两个逻辑不能在一起,分开之后就好了,
已解决
错误代码 1300002
通常表示窗口显示失败,可能原因包括:
- 权限问题:确保应用已获取悬浮窗权限。在设置中检查并授予相关权限。
- 窗口配置错误:检查窗口的布局、尺寸等配置是否符合系统要求。
- 系统资源不足:系统资源(如内存)不足可能导致窗口无法显示,尝试关闭其他应用释放资源。
- API调用错误:确保调用悬浮窗API的代码正确,参数合法。
建议逐步排查以上问题,或参考官方文档获取更详细的错误信息。