HarmonyOS 如何使用scheme协议拉起应用指定频道?

HarmonyOS 如何使用scheme协议拉起应用指定频道?

HarmonyOS
2024-11-21 11:17:31
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple
// 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[]; 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
分享
微博
QQ
微信
回复
2024-11-21 16:51:27
相关问题
H5通过url scheme拉起对应应用
1673浏览 • 1回复 待解决
HarmonyOS 浏览器不能通过scheme拉起app
1656浏览 • 1回复 待解决
HarmonyOS 如何拉起图库中的指定图片
611浏览 • 1回复 待解决
如何拉起拨号界面以及指定号码?
1911浏览 • 2回复 待解决
如何拉起拨号界面并指定号码
2932浏览 • 1回复 待解决
HarmonyOS 如何拉起相机应用
789浏览 • 1回复 待解决
HarmonyOS 如何拉起应用市场?
1132浏览 • 1回复 待解决
如何拉起短信界面并指定联系人
2923浏览 • 1回复 待解决
如何拉起短信界面然后指定联系人?
1437浏览 • 2回复 待解决
HarmonyOS APP中如何使用MQTT协议
1035浏览 • 1回复 待解决
arkts中如何使用mqtt协议
418浏览 • 1回复 待解决
如何拉起应用市场界面
3765浏览 • 1回复 待解决
HarmonyOS webview拉起应用
1376浏览 • 1回复 待解决