鸿蒙服务卡片教程
https://developer.huawei.com/consumer/cn/forum/topic/0201594810293550451
https://blog.csdn.net/qq_33259323/article/details/117967646
我这里只提供思路,和逻辑,教程因为上架中而且上面都有我就别写了
1.创建卡片数据库和卡片表
2.创建JS卡片和卡片的Ability
3.创建弹幕卡片编辑页面FA
4.创建弹幕卡片编辑PA
5.编写JS卡片
6.编写卡片编辑页面
7.配置小卡片,把编辑页面的ability加入卡片配置,修改卡片的名字等等
8.处理卡片创建
卡片创建时把ID存在卡片数据库
9.编写卡片编辑逻辑
JS获取input输入mid,点击搜索请求,获取主播信息数据,把请求返回数据设置到页面上去
https://api.bilibili.com/x/space/acc/info?mid=123456
{
"<span class="hljs-attribute">code</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">message</span>": <span class="hljs-value"><span class="hljs-string">"0"</span></span>,
"<span class="hljs-attribute">ttl</span>": <span class="hljs-value"><span class="hljs-number">1</span></span>,
"<span class="hljs-attribute">data</span>": <span class="hljs-value">{
"<span class="hljs-attribute">mid</span>": <span class="hljs-value"><span class="hljs-number">123456</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"哦哈哟"</span></span>,
"<span class="hljs-attribute">sex</span>": <span class="hljs-value"><span class="hljs-string">"男"</span></span>,
"<span class="hljs-attribute">face</span>": <span class="hljs-value"><span class="hljs-string">"http://i0.hdslb.com/bfs/face/2fa84e04217f91399fb93d7eb2716a5eee55ec78.jpg"</span></span>,
"<span class="hljs-attribute">sign</span>": <span class="hljs-value"><span class="hljs-string">"不卖 老板我不卖"</span></span>,
"<span class="hljs-attribute">rank</span>": <span class="hljs-value"><span class="hljs-number">10000</span></span>,
"<span class="hljs-attribute">level</span>": <span class="hljs-value"><span class="hljs-number">5</span></span>,
"<span class="hljs-attribute">jointime</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">moral</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">silence</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">birthday</span>": <span class="hljs-value"><span class="hljs-string">"01-01"</span></span>,
"<span class="hljs-attribute">coins</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">fans_badge</span>": <span class="hljs-value"><span class="hljs-literal">false</span></span>,
"<span class="hljs-attribute">official</span>": <span class="hljs-value">{
"<span class="hljs-attribute">role</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">title</span>": <span class="hljs-value"><span class="hljs-string">""</span></span>,
"<span class="hljs-attribute">desc</span>": <span class="hljs-value"><span class="hljs-string">""</span></span>,
"<span class="hljs-attribute">type</span>": <span class="hljs-value">-<span class="hljs-number">1</span>
</span>}</span>,
"<span class="hljs-attribute">vip</span>": <span class="hljs-value">{
"<span class="hljs-attribute">type</span>": <span class="hljs-value"><span class="hljs-number">2</span></span>,
"<span class="hljs-attribute">status</span>": <span class="hljs-value"><span class="hljs-number">1</span></span>,
"<span class="hljs-attribute">due_date</span>": <span class="hljs-value"><span class="hljs-number">2044454400000</span></span>,
"<span class="hljs-attribute">vip_pay_type</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">theme_type</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">label</span>": <span class="hljs-value">{
"<span class="hljs-attribute">path</span>": <span class="hljs-value"><span class="hljs-string">"http://i0.hdslb.com/bfs/vip/label_annual.png"</span></span>,
"<span class="hljs-attribute">text</span>": <span class="hljs-value"><span class="hljs-string">"十年大会员"</span></span>,
"<span class="hljs-attribute">label_theme</span>": <span class="hljs-value"><span class="hljs-string">"ten_annual_vip"</span></span>,
"<span class="hljs-attribute">text_color</span>": <span class="hljs-value"><span class="hljs-string">"#FFFFFF"</span></span>,
"<span class="hljs-attribute">bg_style</span>": <span class="hljs-value"><span class="hljs-number">1</span></span>,
"<span class="hljs-attribute">bg_color</span>": <span class="hljs-value"><span class="hljs-string">"#FB7299"</span></span>,
"<span class="hljs-attribute">border_color</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>}</span>,
"<span class="hljs-attribute">avatar_subscript</span>": <span class="hljs-value"><span class="hljs-number">1</span></span>,
"<span class="hljs-attribute">nickname_color</span>": <span class="hljs-value"><span class="hljs-string">"#FB7299"</span></span>,
"<span class="hljs-attribute">role</span>": <span class="hljs-value"><span class="hljs-number">7</span></span>,
"<span class="hljs-attribute">avatar_subscript_url</span>": <span class="hljs-value"><span class="hljs-string">"http://i0.hdslb.com/bfs/vip/icon_Certification_big_member_22_3x.png"</span>
</span>}</span>,
"<span class="hljs-attribute">pendant</span>": <span class="hljs-value">{
"<span class="hljs-attribute">pid</span>": <span class="hljs-value"><span class="hljs-number">462</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"地中海"</span></span>,
"<span class="hljs-attribute">image</span>": <span class="hljs-value"><span class="hljs-string">"http://i0.hdslb.com/bfs/face/c8735da69314d54144a0b1fde5d69676ce72d7b6.png"</span></span>,
"<span class="hljs-attribute">expire</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">image_enhance</span>": <span class="hljs-value"><span class="hljs-string">"http://i0.hdslb.com/bfs/face/c8735da69314d54144a0b1fde5d69676ce72d7b6.png"</span></span>,
"<span class="hljs-attribute">image_enhance_frame</span>": <span class="hljs-value"><span class="hljs-string">""</span>
</span>}</span>,
"<span class="hljs-attribute">nameplate</span>": <span class="hljs-value">{
"<span class="hljs-attribute">nid</span>": <span class="hljs-value"><span class="hljs-number">88</span></span>,
"<span class="hljs-attribute">name</span>": <span class="hljs-value"><span class="hljs-string">"十年大会员"</span></span>,
"<span class="hljs-attribute">image</span>": <span class="hljs-value"><span class="hljs-string">"http://i1.hdslb.com/bfs/face/5b04cc2fb1c479874cac145eb7ac7098a1e081d9.png"</span></span>,
"<span class="hljs-attribute">image_small</span>": <span class="hljs-value"><span class="hljs-string">"http://i2.hdslb.com/bfs/face/b44b390de6b68a9ac7087b3bef07ad90a46101c4.png"</span></span>,
"<span class="hljs-attribute">level</span>": <span class="hljs-value"><span class="hljs-string">"稀有勋章"</span></span>,
"<span class="hljs-attribute">condition</span>": <span class="hljs-value"><span class="hljs-string">"累计开通大会员总时长\u003e=10年即可获得"</span>
</span>}</span>,
"<span class="hljs-attribute">user_honour_info</span>": <span class="hljs-value">{
"<span class="hljs-attribute">mid</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">colour</span>": <span class="hljs-value"><span class="hljs-literal">null</span></span>,
"<span class="hljs-attribute">tags</span>": <span class="hljs-value"><span class="hljs-literal">null</span>
</span>}</span>,
"<span class="hljs-attribute">is_followed</span>": <span class="hljs-value"><span class="hljs-literal">false</span></span>,
"<span class="hljs-attribute">top_photo</span>": <span class="hljs-value"><span class="hljs-string">"http://i2.hdslb.com/bfs/space/cb1c3ef50e22b6096fde67febe863494caefebad.png"</span></span>,
"<span class="hljs-attribute">theme</span>": <span class="hljs-value">{}</span>,
"<span class="hljs-attribute">sys_notice</span>": <span class="hljs-value">{}</span>,
"<span class="hljs-attribute">live_room</span>": <span class="hljs-value">{
"<span class="hljs-attribute">roomStatus</span>": <span class="hljs-value"><span class="hljs-number">1</span></span>,
"<span class="hljs-attribute">liveStatus</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">url</span>": <span class="hljs-value"><span class="hljs-string">"https://live.bilibili.com/5052841"</span></span>,
"<span class="hljs-attribute">title</span>": <span class="hljs-value"><span class="hljs-string">""</span></span>,
"<span class="hljs-attribute">cover</span>": <span class="hljs-value"><span class="hljs-string">""</span></span>,
"<span class="hljs-attribute">online</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">roomid</span>": <span class="hljs-value"><span class="hljs-number">5052841</span></span>,
"<span class="hljs-attribute">roundStatus</span>": <span class="hljs-value"><span class="hljs-number">0</span></span>,
"<span class="hljs-attribute">broadcast_type</span>": <span class="hljs-value"><span class="hljs-number">0</span>
</span>}
</span>}
</span>} 复制
点击确认调用弹幕卡片编辑PA,把请求返回数据整理后发给PA,在PA中把主播信息数据存到对应卡片的数据库中
10.定时更新逻辑
从数据库中读取卡片列表设置数据,在项目中添加okhttp包
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
在定时更新逻辑中请求获取直播间弹幕,其中roomid是从编辑页面获取到的主播信息数据中拿到的
https://api.live.bilibili.com/xlive/web-room/v1/dM/gethistory?roomid=23208586
{"code":0,"data":{"admin":[{"text":"憋死我了,我要好好夸夸你","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:12:30","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1292465055","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088350,"ct":"817C0F07"},"lpl":0},{"text":"我再也不骂人了","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:13:14","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-659451217","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088394,"ct":"9502212"},"lpl":0},{"text":"大主播不都这视角","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:13:21","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1148253546","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088401,"ct":"C48DB3CB"},"lpl":0},{"text":"我今天出门溜达,看到一帮老太太扭秧歌,","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:14:15","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-772415582","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088455,"ct":"C0521CE4"},"lpl":0},{"text":"老亲切了,好久没看到了","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:14:24","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-1847411289","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088464,"ct":"D0DF3B47"},"lpl":0},{"text":"自♂由","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:15:19","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1116172795","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088519,"ct":"A3818B2B"},"lpl":0},{"text":"下播去吃饭","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:15:37","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-1409718989","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088537,"ct":"7CB62F91"},"lpl":0},{"text":"要不你直播吃饭吧","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:16:17","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1157232204","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088577,"ct":"E1B3CECB"},"lpl":0},{"text":"晚上早点睡觉,别老熬夜","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:17:09","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-2010908663","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088629,"ct":"1298F360"},"lpl":0},{"text":"拜拜,啵啵","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:18:13","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-460272504","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088693,"ct":"4649FD22"},"lpl":0}],"room":[{"text":"憋死我了,我要好好夸夸你","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:12:30","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1292465055","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088350,"ct":"817C0F07"},"lpl":0},{"text":"我再也不骂人了","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:13:14","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-659451217","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088394,"ct":"9502212"},"lpl":0},{"text":"大主播不都这视角","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:13:21","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1148253546","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088401,"ct":"C48DB3CB"},"lpl":0},{"text":"我今天出门溜达,看到一帮老太太扭秧歌,","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:14:15","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-772415582","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088455,"ct":"C0521CE4"},"lpl":0},{"text":"老亲切了,好久没看到了","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:14:24","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-1847411289","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088464,"ct":"D0DF3B47"},"lpl":0},{"text":"自♂由","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:15:19","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1116172795","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088519,"ct":"A3818B2B"},"lpl":0},{"text":"下播去吃饭","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:15:37","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-1409718989","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088537,"ct":"7CB62F91"},"lpl":0},{"text":"要不你直播吃饭吧","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:16:17","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"1157232204","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088577,"ct":"E1B3CECB"},"lpl":0},{"text":"晚上早点睡觉,别老熬夜","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:17:09","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-2010908663","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088629,"ct":"1298F360"},"lpl":0},{"text":"拜拜,啵啵","uid":150016850,"nickname":"罪恶克星王狗蛋","uname_color":"#00D1F1","timeline":"2021-07-12 19:18:13","isadmin":1,"vip":0,"svip":0,"medal":[23,"鬼来了","2999狼外婆",23208586,1725515,"",0,6809855,1725515,5414290,3,1,71598153],"title":["",""],"user_level":[12,0,6406234,"\u003e50000"],"rank":10000,"teamid":0,"rnd":"-460272504","user_title":"","guard_level":3,"bubble":5,"bubble_color":"#1453BAFF,#4C2263A2,#3353BAFF","check_info":{"ts":1626088693,"ct":"4649FD22"},"lpl":0}]},"message":"","msg":""}
|