且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何让用户在 Android 中使用 Intent 仅选择本地文件?

更新时间:2023-12-06 11:41:10

请尝试使用 Intent.EXTRA_LOCAL_ONLY 喜欢
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
如果您设备中的图库应用支持,则只会显示本地存储中的文件.如果图库应用不支持上述意图,您可以在检查图库应用返回的文件路径的文件长度后向用户显示错误消息.

Please try using Intent.EXTRA_LOCAL_ONLY like
intent.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
If the gallery app in your device supports it, only files in local storage will be displayed. If the gallery app does not support the above intent, you can show an error message to the user after checking the file length of the returned file path from gallery app.