【问题描述】
HarmonyOS如何添加创建快捷键?
【问题答案】
参考资料
配置文件说明(Java)
config.json配置
config.json添加shortcuts标签,代码如下
"shortcuts": [
{
"shortcutId": "myid",
"label": "$string:entry_MainAbility",
"intents": [
{
"targetBundle": "com.changjian.myapplication",
"targetClass": "com.changjian.myapplication.MainAbility"
java代码实现
在Java代码获取添加,代码如下
null;
try {
shortcutInfo = getBundleManager().getShortcutInfos(getBundleName()).get(0);
shortcutInfo.setLabel("测试");
} catch (RemoteException e) {
e.printStackTrace();
}
shortcutInfo.setHostAbilityName(MainAbility.class.getName());
this.getBundleManager().addHomeShortcut(shortcutInfo);
运行效果
欲了解更多更全技术文章,欢迎访问https://developer.huawei.com/consumer/cn/forum/?ha_source=zzh