HarmonyOS 鸿蒙Next:想让APP出现在系统文件分享的目标选项中,在module.json5中进行了配置,但调试并无效果,大家伙帮我看看哪里有问题
HarmonyOS 鸿蒙Next:想让APP出现在系统文件分享的目标选项中,在module.json5中进行了配置,但调试并无效果,大家伙帮我看看哪里有问题
<markdown _ngcontent-cpt-c149="" class="markdownPreContainer">
初衷是希望系统应用文件管理中 可以实现用户批量选择本地文件,然后分享 给本APP使用。 我根据接口文档进行了尝试,但是真机调试发现并未起效,劳烦大佬们帮我看看为什么问题在哪里,或者说除了这个配置还有没有其他前提条件。
- API版本:5.0.1
- 鸿蒙版本:5.0.0
- 设备型号:华为nova12 UItra
以下是我 entry 的module.json5 文件中的相关配置
{
"module": {
……
"abilities": [
{
"name": "EntryAbility",
"srcEntry": "./ets/entryability/EntryAbility.ets",
"description": "$string:ability_desc",
"icon": "$media:layered_image",
"label": "$string:ability_label",
"startWindowIcon": "$media:startIcon",
"startWindowBackground": "$color:start_window_background",
"exported": true,
"backgroundModes": [
"audioPlayback"
],
"skills": [
{
"entities": [
"entity.system.home"
],
"actions": [
"ohos.want.action.sendData"
],
"uris": [
{
"scheme": "file",
"type": "general.entity",
"maxFileSupported": 100
},
{
"scheme": "file",
"type": "general.audio",
"maxFileSupported": 100
},
]
}
]
}
],
……
}
}
在 entry 的EntryAbility 中也进行了简单打印
import { AbilityConstant, UIAbility, Want } from '@kit.AbilityKit';
import { hilog } from '@kit.PerformanceAnalysisKit';
import { systemShare } from '@kit.ShareKit';
import { BusinessError } from '@kit.BasicServicesKit';
export default class EntryAbility extends UIAbility {
private mainWindow ?: <span class="hljs-built_in">window</span>.Window;
onCreate(<span class="hljs-attribute">want</span>: Want, <span class="hljs-attribute">launchParam</span>: AbilityConstant.LaunchParam): <span class="hljs-reserved">void</span> {
AppStorage.setOrCreate(<span class="hljs-string">'context'</span>, <span class="hljs-keyword">this</span>.context)
hilog.info(<span class="hljs-number">0x0000</span>, <span class="hljs-string">'testTag'</span>, <span class="hljs-string">'%{public}s'</span>, <span class="hljs-string">'Ability onCreate'</span>);
systemShare.getSharedData<span class="hljs-function"><span class="hljs-params">(want)</span>.<span class="hljs-title">then</span><span class="hljs-params">((data: systemShare.SharedData) => {
data.getRecords().forEach((record: systemShare.SharedRecord) => {
<span class="hljs-regexp">//</span> 处理分享数据
<span class="hljs-built_in">console</span>.warn(<span class="hljs-string">"RecvShareData:"</span>, record.label);
});
})</span>.<span class="hljs-title">catch</span><span class="hljs-params">((error: BusinessError) => {
<span class="hljs-built_in">console</span>.error(`<span class="javascript">Failed to getSharedData. Code: ${error.code}, message: ${error.message}</span>`);
})</span>
}
...
}
更多关于HarmonyOS 鸿蒙Next:想让APP出现在系统文件分享的目标选项中,在module.json5中进行了配置,但调试并无效果,大家伙帮我看看哪里有问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html
这边有一个关于分享的demo,你可以参考看下:
https://gitee.com/harmonyos_samples/share-kit_-sample-code_-clientdemo_-arkts
更多关于HarmonyOS 鸿蒙Next:想让APP出现在系统文件分享的目标选项中,在module.json5中进行了配置,但调试并无效果,大家伙帮我看看哪里有问题的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html
在HarmonyOS鸿蒙Next系统中,若想让APP出现在系统文件分享的目标选项中,你需要在module.json5
文件中正确配置share_targets
字段。以下是一些可能导致配置无效的原因及检查要点:
-
配置格式:确保
module.json5
文件中的share_targets
字段格式正确。它应该是一个数组,每个元素包含mimeType
(表示接受的MIME类型)、action
(表示处理分享动作的方法)等信息。 -
权限声明:检查是否在
module.json5
中声明了必要的权限,如ohos.permission.READ_MEDIA
或ohos.permission.WRITE_MEDIA
,这取决于你的APP需要访问的文件类型。 -
模块依赖:确认你的APP已经包含了处理分享功能所必需的模块依赖。
-
重启调试:在修改
module.json5
后,确保重启IDE和调试设备,以使配置生效。 -
日志检查:查看调试日志,检查是否有与分享功能相关的错误信息或警告。
如果上述检查均无问题,但配置仍无效,可能是系统或IDE的bug。此时,你可以尝试清除IDE缓存、重启设备,或更新HarmonyOS SDK到最新版本。如果问题依旧没法解决请联系官网客服,官网地址是:https://www.itying.com/category-93-b0.html