美文网首页
鸿蒙调用第三方应用打开文件

鸿蒙调用第三方应用打开文件

作者: CentForever | 来源:发表于2022-10-30 13:54 被阅读0次

    config.json

          {
            "name": "ohos.data.file.FileAbility",
            "icon": "$media:icon",
            "type": "data",
            "uri": "dataability://ohos.data.file.FileAbility",
            "grantPermission": true
          }
    
    image.png

    fileability.json

    {
      "paths": [
        {
          "tag": "fileability-external-path",
          "name": "external_storage_root",
          "path": "."
        },
        {
          "tag": "fileability-files-path",
          "name": "files-path",
          "path": "."
        },
        {
          "tag": "fileability-cache-path",
          "name": "external_file_path",
          "path": "."
        },
        {
          "tag": "fileability-external-cache-path",
          "name": "external_cache_path",
          "path": "."
        },
        {
          "tag": "fileability-root-path",
          "name": "root-path",
          "path": "."
        }
      ]
    }
    

    代码

    {
            try {
                //获取文件类型
                String type = getMIMEType(file);
                Intent intent = new Intent();
                intent.setType(type);
                Uri fileUri = FileAbility.getUriViaFile(mContext, "/ohos.data.file.FileAbility", file);
                Operation operation = new Intent.OperationBuilder()
                        .withAction(IntentConstants.ACTION_VIEW_DATA)
                        .withFlags(Intent.FLAG_ABILITY_NEW_MISSION)
                        .withUri(fileUri).build();
                intent.setOperation(operation);
                mContext.startAbility(intent, 0);
            } catch (Exception e) {
                Log.e(TAG, "openFile: " + e.getMessage());
            }
        }
    

    相关文章

      网友评论

          本文标题:鸿蒙调用第三方应用打开文件

          本文链接:https://www.haomeiwen.com/subject/ajoktdtx.html