中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
HarmonyOS 如何使用scheme协议拉起应用指定频道?
微信扫码分享
// A应用 import { common, Want } from '@kit.AbilityKit'; @Entry @Component struct Scheme_App { @State message: string = 'Hello World'; build() { Column() { Button(this.message) .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .onClick(()=>{ let paylink = 'sohunews://pr/tab://tabName=hotChart'; let want: Want = { uri: paylink }; let context = getContext(this) as common.UIAbilityContext; context.startAbility(want); }) } .height('100%') .width('100%') } } // B应用 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); let scheme = want.uri?.toString() if (scheme?.includes('hotChart')) { // const context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; AppStorage.setOrCreate('hotChart', 'pages/List_Sticky') hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); } } "abilities": [ { "name": "EntryAbility", "srcEntry": "./ets/entryability/EntryAbility.ets", "description": "$string:EntryAbility_desc", "icon": "$media:layered_image", "label": "$string:EntryAbility_label", "startWindowIcon": "$media:startIcon", "startWindowBackground": "$color:start_window_background", "exported": true, "skills": [ { "entities": [ "entity.system.home" ], "actions": [ "action.system.home" ], "uris": [ { "scheme": 'sohunews://pr/tab://tabName=hotChart' } ] } ] } ], // B应用被拉起跳转的页面 @Entry @Component struct List_Sticky { private timeTable: TimeTable[] = [ { title: '星期一', projects: ['语文', '数学', '英语'] }, { title: '星期二', projects: ['物理', '化学', '生物'] }, { title: '星期三', projects: ['历史', '地理', '政治'] }, { title: '星期四', projects: ['美术', '音乐', '体育'] } ] @Builder itemHead(text: string) { Text(text) .fontSize(20) .backgroundColor(0xAABBCC) .width("100%") .padding(10) } @Builder itemFoot(num: number) { Text('共' + num + "节课") .fontSize(16) .backgroundColor(0xAABBCC) .width("100%") .padding(5) } build() { Column() { List({ space: 20 }) { ForEach(this.timeTable, (item: TimeTable) => { ListItemGroup({ header: this.itemHead(item.title), footer: this.itemFoot(item.projects.length) }) { ForEach(item.projects, (project: string) => { ListItem() { Text(project) .width("100%") .height(100) .fontSize(20) .textAlign(TextAlign.Center) .backgroundColor(0xFFFFFF) } }, (item: string) => item) } .divider({ strokeWidth: 1, color: Color.Blue }) // 每行之间的分界线 }) } .width('90%') .sticky(StickyStyle.Header | StickyStyle.Footer) .scrollBar(BarState.Off) }.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 }) } } interface TimeTable { title: string; projects: string[]; }