相关疑难解决方法(0)

如何使用MediaStore在Android Q中保存图像?

这是新的Android Q 范围存储的链接。

根据此Android开发者最佳实践博客storing shared media files(这是我的情况)应使用MediaStore API完成。

深入研究文档,我找不到相关功能。

这是我在科特林的审判:

val bitmap = getImageBitmap() // I have a bitmap from a function or callback or whatever
val name = "example.png" // I have a name

val picturesDirectory = getExternalFilesDir(Environment.DIRECTORY_PICTURES)!!

// Make sure the directory "Android/data/com.mypackage.etc/files/Pictures" exists
if (!picturesDirectory.exists()) {
    picturesDirectory.mkdirs()
}

try {
    val out = FileOutputStream(File(picturesDirectory, name))
    bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)

    out.flush()
    out.close()

} catch(e: Exception) {
    // handle the error
}
Run Code Online (Sandbox Code Playgroud)

结果是,Android/data/com.mypackage.etc/files/Pictures/example.png …

java android image mediastore kotlin

13
推荐指数
3
解决办法
2680
查看次数

手动将本地文件添加到"下载"应用程序

我的应用程序需要下载文件,我正在查看DownloadManager,但它有一些不适合我的情况(身份验证,命名方案,验证)的限制,所以我制作了自定义下载引擎.

是否可以手动将使用我的引擎下载的文件(因此使用本地URL)添加到下载系统应用程序的列表中?我的理解是列表由系统内容提供者填充.是否可以在没有DownloadManager尝试下载文件的情况下向其中添加记录?

谢谢 ;)

android download download-manager

7
推荐指数
1
解决办法
1104
查看次数

标签 统计

android ×2

download ×1

download-manager ×1

image ×1

java ×1

kotlin ×1

mediastore ×1