Android11(API30)上Android存储访问框架无法工作。
创始人
2024-08-20 09:00:58
0

为了在Android 11上访问外部存储,需要使用新的API来构建一个非常特定的意图。以下是代码示例:

// ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file
// browser.
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
    // Filter to only show results that can be "opened", such as a
    // file (as opposed to a list of contacts or timezones).
    addCategory(Intent.CATEGORY_OPENABLE)

    // Filter to show only images, using the image MIME data type.
    // If one wanted to search for ogg vorbis files, the type would be "audio/ogg".
    // To search for all documents available via installed storage providers,
    // it would be "*/*".
    type = "image/*"
}
startActivityForResult(intent, READ_REQUEST_CODE)

此代码示例中,我们使用Intent.ACTION_OPEN_DOCUMENT 创建一个意图来选择一个文件。该意图包含一个Intent.CATEGORY_OPENABLE过滤器,以确保该文件可以被打开。另外,我们还需要指定我们要搜索的文件类型,例如过滤器中的'image/*”,该意图将打开系统的文件浏览器并让用户选择要打开的文件。

相关内容

热门资讯

推荐透视!wepoker辅助器... 推荐透视!wepoker辅助器最新版本更新内容,广西微乐小程序控制器,机巧教程(有挂方式)-哔哩哔哩...
开挂透视!hhpoker是正规... 开挂透视!hhpoker是正规的吗,微信小程序微乐辅助免费版,窍门教程(有挂攻略)-哔哩哔哩一、hh...
揭露透视!wepokerplu... 揭露透视!wepokerplus作弊,微乐家乡官方免费下载安装,机巧教程(有挂教程)-哔哩哔哩1、玩...
科普透视!hhpoker透视脚... 科普透视!hhpoker透视脚本下载,微乐锄大地脚本,教材教程(详细教程)-哔哩哔哩hhpoker透...
总结透视!hhpoker脚本,... 总结透视!hhpoker脚本,微信小程序微乐房间透视,指引教程(有挂猫腻)-哔哩哔哩1、总结透视!h...
总结透视!wepoker好友局... 总结透视!wepoker好友局透视,微信微乐小程序有窍门吗,演示教程(有挂方式)-哔哩哔哩总结透视!...
揭幕透视!wepoker怎么看... 揭幕透视!wepoker怎么看牌型,微信小程序微乐辅助器免费版v2.0免费,总结教程(有挂功能)-哔...
辅助透视!拱趴大菠萝作弊方法,... 辅助透视!拱趴大菠萝作弊方法,微乐自建房脚本如何下载,窍要教程(有挂透视)-哔哩哔哩1、任何拱趴大菠...
解谜透视!wepoker透视破... 解谜透视!wepoker透视破解版,微乐小程序礼包码,方案教程(真实有挂)-哔哩哔哩1、超多福利:超...
解迷透视!智星德州插件怎么下载... 解迷透视!智星德州插件怎么下载,微信微乐辅助,方式教程(果真有挂)-哔哩哔哩1、进入到智星德州插件怎...