DEV Community

HarmonyOS
HarmonyOS

Posted on

Enabling .bin File Sharing on HarmonyOS with Custom UTDs and Skills (Fix ‘No Available App to Open’)

Read the original article:Enabling .bin File Sharing on HarmonyOS with Custom UTDs and Skills (Fix ‘No Available App to Open’)

Enabling .bin File Sharing on HarmonyOS with Custom UTDs and Skills (Fix ‘No Available App to Open’)

Requirement Description

On phones, long-pressing a .bin file in File Manager and tapping Share shows “No available way to open”. Images/videos invoke apps correctly. We need to enable sharing/receiving of .bin by defining and declaring a custom UTD and updating the target app’s skills so it appears on the share/open sheet.

Background Knowledge

HarmonyOS uses Uniform Data Type Descriptors (UTDs) to identify file/data types. Apps can declare custom UTDs and express support via skills. If no prebuilt UTD exists for a given extension, HarmonyOS may generate a dynamic UTD (prefix flex.). Declaring your own UTD and mapping skills allows your app to appear as a handler for that file type. See Uniform Data Type Descriptors (overview). (Huawei Developer)

Tip: getParamByName() in ArkUI Navigation returns an array because it aggregates params for all same-named destinations in the stack—useful when diagnosing route parameter handling while testing share flows. (Huawei Developer)

Implementation Steps

Declare a skill for opening the file

In your ability’s module.json5, add a skills item indicating you can view files with your custom UTD:

{
  "skills": [
    {
      "actions": [
        "ohos.want.action.viewData"
      ],
      "uris": [
        {
          "scheme": "file",
          "linkFeature": "FileOpen",
          "type": "com.example.myapplication.bin"
        }
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode
  • type equals your custom TypeId from the UTD declaration file.

Provide the custom UTD declaration

Create resources/rawfile/utd.json5 and declare your type:

{
  "UniformDataTypeDeclarations": [
    {
      "TypeId": "com.example.myapplication.bin",
      "BelongingToTypes": [ "general.object" ],
      "FilenameExtensions": [ ".bin" ],
      "MIMETypes": [ "application/octet-stream" ],
      "Description": "My document.",
      "ReferenceURL": "https://www.mycompany.com/my-document"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode
  • - TypeId must be unique (e.g., ${bundleName}.${type}), using only digits, letters, - and ..

(Alternative) Support a dynamic UTD (“flex.*”)

If the sender yields a dynamic UTD for .bin (for example, flex.zh45depjomjuw4), the receiver can also declare a sendData skill for that UTD to appear in the share panel:

{
  "skills": [
    {
      "actions": [ "ohos.want.action.sendData" ],
      "uris": [
        {
          "scheme": "file",
          "utd": "flex.zh45depjomjuw4",
          "maxFileSupported": 1
        }
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode
  • - Dynamic UTDs typically start with flex..

Build, install, and test

  • - Rebuild the app and install.
    • In Files: create or pick a .bin, long-press → Share (or Open with) → your app should appear.
    • If your app is the sender, ensure you set the Want with the matching action/URI/UTD so the platform can resolve the target. See Want references. (Huawei Developer)

Code Snippet

  • module.json5 (skills): see Step 1/3 above.
  • resources/rawfile/utd.json5: see Step 2 above.
// Index.ets — Wearable demo for UTD lookup (.bin) — HarmonyOS 6 / API 19+

import uniformTypeDescriptor from '@ohos.data.uniformTypeDescriptor'

@Entry
@Component
struct Index {
  @State private extInput: string = '.bin'
  @State private detectedUtd: string = ''
  @State private note: string = 'Enter extension (e.g., .bin) and tap Detect.'

  private detect(): void {
    try {
      const utd: string = uniformTypeDescriptor.getUniformDataTypeByFilenameExtension(this.extInput)
      this.detectedUtd = utd
      this.note = utd.startsWith('flex.')
        ? 'Dynamic UTD detected (flex.*). Consider declaring custom TypeId and/or accept this flex.* in skills.'
        : 'Predefined/custom UTD detected. Make sure your skills use this TypeId.'
    } catch (e) {
      this.detectedUtd = ''
      this.note = `Lookup failed: ${JSON.stringify(e)}`
    }
  }

  build() {
    Column({ space: 8 }) {
      Text('UTD Share Demo (Wearable)').fontSize(16).fontWeight(FontWeight.Medium)
        .fontColor(Color.Black)

      Text('Check the UTD the system resolves for an extension.').fontSize(12).opacity(0.8)
        .fontColor(Color.Black)


      Row({ space: 6 }) {
        TextInput({ placeholder: '.bin', text: this.extInput })
          .onChange((v: string) => this.extInput = v)
          .width('60%')
          .fontColor(Color.Black)
          .backgroundColor(Color.White)

        Button('Detect').onClick(() => this.detect())
      }

      Column({ space: 4 }) {
        Text(`UTD: ${this.detectedUtd || '-'}`).fontSize(14)
          .fontColor(Color.Black)

        Text(this.note).fontSize(12).maxLines(3)
          .fontColor(Color.Black)
      }
      .width('100%')
      .padding(8)
      .backgroundColor(0xFFFFFF)
      .borderRadius(12)
    }
    .width('100%')
    .height('100%')
    .padding(12)
    .backgroundColor(0xF0F6FF)
  }
}
Enter fullscreen mode Exit fullscreen mode

Test Results

  • Verified on API 19 Release with HarmonyOS 5.1.1/6 SDK using DevEco Studio 5.1.1+: the app appears on the share/open sheet for .bin.

_bnybny.gif

Limitations or Considerations

  • Choose a stable TypeId; changing it requires coordinated sender/receiver updates.
  • Some sources may still emit dynamic UTDs; handle both custom TypeId and flex.* cases.
  • Keep MIME (application/octet-stream) and extension mapping accurate.
  • For multi-file share, adjust maxFileSupported.

Related Documents or Links

Written by Bunyamin Eymen Alagoz

Top comments (0)