关于harmonyos:一个小白曾经踩过的坑鸿蒙篇

8次阅读

共计 2337 个字符,预计需要花费 6 分钟才能阅读完成。

  1. 应用 startAbility 跨设施启动 Ability
    谬误案例:

    像这样子设置 Operation 的 AbilityName 参数是谬误的, 如下是正确的形式。

    这两个写法的区别在于谬误写法是把 AbilitySlice 的名称当做 AbilityName,在函数 withAbilityName 中只能填写 Ability 的名称,至于要具体启动那个 AbilitySlice 能够有两种办法来管制,一种是通过传参在 Ability 中的 onStart 办法中判断具体要启动哪个 AbilitySlice, 另一种是官网文档中提到的,如下图,文档地址是 https://developer.harmonyos.c…


  1. 获取设施的 udid 中遇到的坑
    在官方论坛中有个很不便的办法获取 udid,文档地址 https://developer.huawei.com/…
    然而我在具体应用时遇到了一种状况,就是有开启近程模拟器的状况下,用 usb 连贯真机获取 udid 时无奈获取 udid,具体的提醒语 error:more than one device/emulator

    这个的意思是有多个设施,起因是因为这是不仅连贯了鸿蒙真机还有近程模拟器,只须要将模拟器关掉即可。
  2. 提醒谬误 Only page can set main route
    在 Ability 的子类中应用 setMainRoute 设置默认启动 AbilitySlice 时报错 only page can set main route, 这是因为误将 config.json 配置文件中对应的 Ability 的 type 设置成了 service,应该改成 page 类型才可能失常运行。
  3. 如何同步实时将 A 设施的输出同步到 B 设施?
    计划:A 设施的 FA 连贯 B 设施的 PA 将 A 设施的输出内容实时得传输到(B)PA,而后(B)PA 操作 B 设施的 FA 实现两部设施的输出内容实时同步。该计划也同样实用于同步拖动 ScrollView 组件。
  4. 一次申请多个动静权限
    一次要申请多种权限时不要用循环申请的形式,而是间接放在数组中集中申请。如下图。
  5. 利用鸿蒙零碎的 AI 能力(通用文字辨认)辨认身份证上的信息
    鸿蒙零碎有很多有用的 AI 能力能够疾速实现很多性能,例如: 辨认身份证上的名字、身份证号码、住址等,话不多说上代码

    private void IDCardOcrDiscern(PixelMap pixelMap)
    {

    AbilitySlice context = this;
    ConnectionCallback connectionCallback = new ConnectionCallback() {

      @Override
      public void onServiceConnect() {ITextDetector textDetector = VisionManager.getTextDetector(context);
          VisionImage image = VisionImage.fromPixelMap(pixelMap);
          ohos.ai.cv.text.Text text = new ohos.ai.cv.text.Text();
          TextConfiguration.Builder builder = new TextConfiguration.Builder();
          builder.setProcessMode(VisionConfiguration.MODE_IN);
          builder.setDetectType(TextDetectType.TYPE_TEXT_DETECT_FOCUS_SHOOT_EF);
          builder.setLanguage(TextConfiguration.CHINESE);
          TextConfiguration configuration = builder.build();
          textDetector.setVisionConfiguration(configuration);
          int result = textDetector.detect(image,text,null);
          if (result != 0) {return;}
          List<TextBlock> list = text.getBlocks();
          if (list.size() == 0) {return;}
          TextBlock textBlock = list.get(0);
          List<TextLine> arrayList = textBlock.getTextLines();
          if (arrayList.size() == 0) {return;}
          String name = "";
          String addr = "";
          String IDNo = "";
          String nameFlag = "姓名";
          String addrFlag = "住址";
          String codeFlag = "公民身份号码";
          boolean firstAddrShow = false;
          for (TextLine textLine :arrayList) {int i = arrayList.indexOf(textLine);
              String str = textLine.getValue();
              if (str.indexOf(nameFlag) > -1) {name = str.replace(nameFlag,"");
              } else if (str.indexOf(addrFlag) > -1) {addr += str.replace(addrFlag,"");
                  firstAddrShow = true;
              } else if (firstAddrShow) {
                  firstAddrShow = false;
                  addr += str.replace(";","");
              } else if (str.indexOf(codeFlag) > -1) {IDNo = str.replace(codeFlag,"");
              }
          }
      }
    

    };
    }

正文完
 0