HarmonyOS应用开发实战--如何打开相册和音频列表

发布于 2021-11-9 11:04
浏览
1收藏

1.打开相册

private void selectPic() {
    Intent intent = new Intent();
    Operation opt=new Intent.OperationBuilder().withAction("android.intent.action.GET_CONTENT").build();
    intent.setOperation(opt);
    intent.addFlags(Intent.FLAG_NOT_OHOS_COMPONENT);
    intent.setType("image/*");
    startAbilityForResult(intent, imgRequestCode);
}

2.打开音频

    Intent intent = new Intent();
    Operation opt=new Intent.OperationBuilder().withAction("android.intent.action.GET_CONTENT").build();
    intent.setOperation(opt);
    intent.addFlags(Intent.FLAG_NOT_OHOS_COMPONENT);
    intent.setType("image/*");
    startAbilityForResult(intent, imgRequestCode);
}

3.获取选中的文件

protected void onAbilityResult(int requestCode, int resultCode, Intent resultData) {

    HiLog.info(label,"MainAbility::onAbilityResult");

    if(requestCode==imgRequestCode)
    {
        HiLog.info(label,"选择文件getUriString:"+resultData.getUriString());
  }
}

标签
HarmonyOS应用开发实战--如何打开相册和音.docx 14.08K 15次下载
已于2021-11-9 11:17:10修改
1
收藏 1
回复
举报
回复
添加资源
添加资源将有机会获得更多曝光,你也可以直接关联已上传资源 去关联
    相关推荐