HarmonyOS鸿蒙Next中怎么进行跳转微信,只需要跳转操作就可以,不需要其他功能,文档很难看啊

HarmonyOS鸿蒙Next中怎么进行跳转微信,只需要跳转操作就可以,不需要其他功能,文档很难看啊

let want: Want = { uri: 'wexin://' }
let context = getContext(this) as common.UIAbilityContext

context.startAbility(want, (error) => {})

找到了一篇问答中的这个,但是显示暂无可用打开方式,微信文档中说其他功能才需要申请,拉其应用打开应该不用吧,求方法

4 回复

我用这个可以直接拉起微信,没有任何其他配置。

import { common, Want } from '@kit.AbilityKit';
import { promptAction } from '@kit.ArkUI';

@Entry
@Component
struct Index {
  @State message: string = 'Hello World';

  build() {
    RelativeContainer() {
      Text(this.message)
        .id('HelloWorld')
        .fontSize($r('app.float.page_text_font_size'))
        .fontWeight(FontWeight.Bold)
        .alignRules({
          center: { anchor: '__container__', align: VerticalAlign.Center },
          middle: { anchor: '__container__', align: HorizontalAlign.Center }
        })
        .onClick(() => {
          this.message = 'Welcome';

          const want: Want = { uri: 'weixin://' };
          const context = getContext(this) as common.UIAbilityContext;
          context.startAbility(want)
            .then(() => {
              //拉起成功
              console.info("Open Wechat success.")
            }).catch(() => {
            promptAction.showToast({ message: '当前微信还未安装' })
          })
        })
    }
    .height('100%')
    .width('100%')
  }
}

更多关于HarmonyOS鸿蒙Next中怎么进行跳转微信,只需要跳转操作就可以,不需要其他功能,文档很难看啊的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


好像差不多一样的,但是我的拉不起,你的可以,现在能拉起来了,感谢感谢,

在HarmonyOS(鸿蒙)Next中,跳转到微信的操作可以通过Intent实现。以下是一个简单的代码示例:

import featureAbility from '@ohos.ability.featureAbility';
import wantConstant from '@ohos.ability.wantConstant';

let want = {
    bundleName: 'com.tencent.mm',
    abilityName: 'com.tencent.mm.ui.LauncherUI',
    action: wantConstant.Action.VIEW_ACTION,
    uri: 'weixin://'
};

featureAbility.startAbility(want)
    .then(() => {
        console.log('跳转微信成功');
    })
    .catch((err) => {
        console.error('跳转微信失败', err);
    });

这段代码通过featureAbility.startAbility方法启动微信应用。bundleNameabilityName分别指定了微信的包名和主界面。action设置为VIEW_ACTIONuri则指定了微信的协议。

确保在项目的config.json文件中添加了相应的权限和声明:

{
    "module": {
        "reqPermissions": [
            {
                "name": "ohos.permission.START_ABILITIES_FROM_BACKGROUND"
            }
        ]
    }
}

这段代码实现了从鸿蒙应用跳转到微信的功能。

在HarmonyOS鸿蒙Next中,要跳转到微信,可以使用startAbility方法。具体代码如下:

Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
    .withAction("android.intent.action.VIEW")
    .withUri("weixin://")
    .build();
intent.setOperation(operation);
startAbility(intent);

这段代码会直接跳转到微信应用。确保设备上已安装微信,否则会报错。

回到顶部