HarmonyOS 鸿蒙Next extensionWindow?.createSubWindowWithOptions() 报failed: {"code":1300002}
HarmonyOS 鸿蒙Next extensionWindow?.createSubWindowWithOptions() 报failed: {“code”:1300002}
import { UIExtensionContentSession } from '@kit.AbilityKit';
import { uiExtension, window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
let storage = LocalStorage.getShared()
@Entry(storage)
@Component
struct Extension0010 {
@State message: string = 'EmbeddedUIExtensionAbility 0010';
private session: UIExtensionContentSession | undefined = storage.get('session');
private extensionWindow: uiExtension.WindowProxy | undefined = this.session?.getUIExtensionWindowProxy();
private subWindow: window.Window | undefined = undefined;
private windowStore_index: window.WindowStage | undefined = AppStorage.get('Index_windowStage');
aboutToAppear(): void {
this.extensionWindow?.on('windowSizeChange', (size: window.Size) => {
console.info(`size = ${JSON.stringify(size)}`);
});
this.extensionWindow?.on('avoidAreaChange', (info: uiExtension.AvoidAreaInfo) => {
console.info(`type = ${JSON.stringify(info.type)}, area = ${JSON.stringify(info.area)}`);
});
}
aboutToDisappear(): void {
this.extensionWindow?.off('windowSizeChange');
this.extensionWindow?.off('avoidAreaChange');
}
build() {
Column() {
Text(this.message)
.fontSize(20)
.fontWeight(FontWeight.Bold)
Button("获取系统规避区信息").width('90%').margin({ top: 5, bottom: 5 }).fontSize(16).onClick(() => {
let avoidArea: window.AvoidArea | undefined =
this.extensionWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
AlertDialog.show({ message: `系统规避区: ${JSON.stringify(avoidArea)}` })
console.info(`系统规避区: ${JSON.stringify(avoidArea)}`);
AlertDialog.show({ message: `${this.windowStore_index}` })
})
Button("创建子窗口")
.width('90%')
.margin({ top: 5, bottom: 5 })
.fontSize(16)
.onClick(() => {
this.createSubWindow('testability/pages/UIComponentSpecialcomponentsUiextensioncomponentSubWindow/UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010_1')
})
.id('button')
}.width('100%').height('100%')
}
createSubWindow(url: string) {
const subWindowOpts: window.SubWindowOptions = {
title: 'This is a subwindow',
decorEnabled: false
};
// 创建子窗口
// windowStore_index this.extensionWindow
if (this.extensionWindow === null || this.extensionWindow === undefined) {
console.error(`Create subwindow failed: extensionWindow is null`);
return
} else {
try {
// console.info('Create subwindow BusinessErrorsubwindow'+JSON.stringify(this.extensionWindow))
this.extensionWindow?.createSubWindowWithOptions('uioio1', subWindowOpts)
.then((subWindow) => {
this.subWindow = subWindow;
console.info(`The subwindow has setUIContent start`)
// this.subWindow.loadContent(url, storage, (err, data) => {
this.subWindow.setUIContent(url, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has setUIContent err! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has resize start`)
this.subWindow?.resize(300, 300, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has resize err! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has moveWindowTo start`)
this.subWindow?.moveWindowTo(100, 100, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has resize moveWindowTo! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has showWindow start`)
this.subWindow?.showWindow((err, data) => {
if (err && err.code == 0) {
console.info(`The subwindow has been shown!`);
} else {
console.info(`Failed to show the subwindow!`);
}
});
});
});
})
.catch((error: BusinessError) => {
console.error(`Create subwindowIndex failed: ${JSON.stringify(error)}`);
})
}
catch (e) {
console.error('失败' + JSON.stringify(e))
}
}
}
}
更多关于HarmonyOS 鸿蒙Next extensionWindow?.createSubWindowWithOptions() 报failed: {"code":1300002}的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
你的代码太乱了,没法用啊,可以插入代码段吗
更多关于HarmonyOS 鸿蒙Next extensionWindow?.createSubWindowWithOptions() 报failed: {"code":1300002}的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
请问是已经解决了吗
import { UIExtensionContentSession } from '@kit.AbilityKit';
import { uiExtension, window } from '@kit.ArkUI';
import { BusinessError } from '@kit.BasicServicesKit';
let storage = LocalStorage.getShared()
@Entry(storage)
@Component
struct Extension0010 {
@State message: string = 'EmbeddedUIExtensionAbility 0010';
private session: UIExtensionContentSession | undefined = storage.get<UIExtensionContentSession>('session');
private extensionWindow: uiExtension.WindowProxy | undefined = this.session?.getUIExtensionWindowProxy();
private subWindow: window.Window | undefined = undefined;
private windowStore_index: window.WindowStage | undefined = AppStorage.get('Index_windowStage');
aboutToAppear(): void {
this.extensionWindow?.on('windowSizeChange', (size: window.Size) => {
console.info(`size = ${JSON.stringify(size)}`);
});
this.extensionWindow?.on('avoidAreaChange', (info: uiExtension.AvoidAreaInfo) => {
console.info(`type = ${JSON.stringify(info.type)}, area = ${JSON.stringify(info.area)}`);
});
}
aboutToDisappear(): void {
this.extensionWindow?.off('windowSizeChange');
this.extensionWindow?.off('avoidAreaChange');
}
build() {
Column() {
Text(this.message)
.fontSize(20)
.fontWeight(FontWeight.Bold)
Button("获取系统规避区信息").width('90%').margin({ top: 5, bottom: 5 }).fontSize(16).onClick(() => {
let avoidArea: window.AvoidArea | undefined =
this.extensionWindow?.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM);
AlertDialog.show({ message: `系统规避区: ${JSON.stringify(avoidArea)}` })
console.info(`系统规避区: ${JSON.stringify(avoidArea)}`);
AlertDialog.show({ message: `${this.windowStore_index}` })
})
Button("创建子窗口")
.width('90%')
.margin({ top: 5, bottom: 5 })
.fontSize(16)
.onClick(() => {
this.createSubWindow('testability/pages/UIComponentSpecialcomponentsUiextensioncomponentSubWindow/UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010_1')
})
.id('button')
}.width('100%').height('100%')
}
createSubWindow(url: string) {
const subWindowOpts: window.SubWindowOptions = {
title: 'This is a subwindow',
decorEnabled: false
};
// 创建子窗口
// windowStore_index this.extensionWindow
if (this.extensionWindow === null || this.extensionWindow === undefined) {
console.error(`Create subwindow failed: extensionWindow is null`);
return
} else {
try {
// console.info('Create subwindow BusinessErrorsubwindow'+JSON.stringify(this.extensionWindow))
this.extensionWindow?.createSubWindowWithOptions('uioio1', subWindowOpts)
.then((subWindow) => {
this.subWindow = subWindow;
console.info(`The subwindow has setUIContent start`)
// this.subWindow.loadContent(url, storage, (err, data) => {
this.subWindow.setUIContent(url, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has setUIContent err! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has resize start`)
this.subWindow?.resize(300, 300, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has resize err! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has moveWindowTo start`)
this.subWindow?.moveWindowTo(100, 100, (err, data) => {
if (err && err.code != 0) {
console.info(`The subwindow has resize moveWindowTo! +${err.code + err.message}`);
return;
}
console.info(`The subwindow has showWindow start`)
this.subWindow?.showWindow((err, data) => {
if (err && err.code == 0) {
console.info(`The subwindow has been shown!`);
} else {
console.error(`Failed to show the subwindow!`);
}
});
});
});
});
})
.catch((error: BusinessError) => {
console.error(`Create subwindowIndex failed: ${JSON.stringify(error)}`);
})
} catch (e) {
console.error('失败' + JSON.stringify(e))
}
}
}
}
@Entry
@Component
struct UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010_1 {
@State message: string = 'EmbeddedUIExtensionAbility 0010_1';
build() {
Column() {
Text(this.message)
.fontSize(40)
.fontWeight(FontWeight.Bold)
}.width('100%').height('100%')
}
}
@Entry
@Component
struct UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010 {
@State message: string = 'Message: ';
private want: Want = {
bundleName: "com.example.uicompare",
abilityName: "UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010Ability",
parameters: {
"ability.want.params.uiExtensionType": "sys/commonUI",
}
};
build() {
Row() {
Column() {
Text(this.message).fontSize(30)
UIExtensionComponent(this.want)
.width('100%')
.height('90%')
.onTerminated((info) => {
this.message = 'Termination: code = ' + info.code + ', want = ' + JSON.stringify(info.want);
})
.onError((error) => {
this.message = 'Error: code = ' + error.code;
})
}
.width('100%')
}
.height('100%')
}
}
import { EmbeddedUIExtensionAbility, UIExtensionAbility, UIExtensionContentSession, Want } from '@kit.AbilityKit';
const TAG: string = '[UIExtensionAbility]'
export default class UIComponentSpecialcomponentsUiextensioncomponentSubWindow0010Ability extends UIExtensionAbility {
onCreate() {
console.info(TAG, `onCreate`);
}
onForeground() {
console.info(TAG, `onForeground`);
}
onBackground() {
console.info(TAG, `onBackground`);
}
onDestroy() {
console.info(TAG, `onDestroy`);
}
onSessionCreate(want: Want, session: UIExtensionContentSession) {
console.info(TAG, `onSessionCreate, want: ${JSON.stringify(want)}`);
let param: Record<string, UIExtensionContentSession> = {
'session': session
};
let storage: LocalStorage = new LocalStorage(param);
session.loadContent('testability/pages/UIComponentSpecialcomponentsUiextensioncomponentSubWindow/Extension0010', storage);
}
}
针对您提到的HarmonyOS(鸿蒙)中Next extensionWindow?.createSubWindowWithOptions()
方法返回failed: {"code":1300002}
的问题,这通常表明在创建子窗口时遇到了某种权限或配置错误。
-
权限检查:确保您的应用已正确声明了创建子窗口所需的权限。在鸿蒙系统中,某些操作可能需要特定的权限,这些权限需要在应用的
config.json
文件中声明。 -
配置检查:检查传递给
createSubWindowWithOptions()
方法的配置参数。确保所有必要的参数都已正确设置,并且符合鸿蒙系统的要求。特别是窗口类型、大小、位置等参数,需要确保它们在允许的范围内。 -
系统限制:确认您的设备或模拟器是否支持创建子窗口。某些设备或系统版本可能由于硬件限制或系统策略而不支持此功能。
-
API版本:确保您使用的鸿蒙SDK版本支持您正在尝试使用的API。如果API在新版本中已更改或废弃,您可能需要更新您的SDK或调整代码。
如果问题依旧没法解决请联系官网客服,官网地址是: