小编Rub*_*ick的帖子

在 DownloadManager 上下载并在 setDestinationInExternalFilesDir() 中保存文件在 Android 10 上不起作用

DownloadManager用来保存来自服务器的 mp4。我将文件保存在storage/Emulated/0/Android/data/<packagename>/files/.Videos. 我注意到在 Android 9 和 android 11 上成功下载了它。但在 Android 10 中失败了。我试图将它附在try{}catch{}方法上,但在日志上看不到任何内容。我也尝试添加android:requestLegacyExternalStorage="true"我的Android Manifest.xml但错误仍然发生。我还提到了他/她使用的这个问题,setDestinationUri()但我仍然找不到方法。顺便说一句,这是我的片段DownloadRequest

val path: String =
            context.getExternalFilesDir(null)?.absolutePath + "/" + ".Videos"

val downloadmanager: DownloadManager =
            context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
        val request: DownloadManager.Request = DownloadManager.Request(uri)
            .setTitle(videoName)
            .setDescription("Downloading")
            .setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE)
            .setDestinationInExternalFilesDir(context, ".Videos", "test1.mp4")
            //.setDestinationUri(Uri.fromFile(File(path, "test.mp4")))
            //.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS,videoName)
        val downloadId = downloadmanager.enqueue(request)
Run Code Online (Sandbox Code Playgroud)

非常感谢所有回应:)

android download-manager kotlin android-10.0

4
推荐指数
1
解决办法
725
查看次数

具有千位分隔符的DecimalFormatter 0值返回.00

我在android应用程序上的结果格式存在问题。

我使用DecimalFormat的格式为"###,###.00"。现在,100000.0返回的大数100,000.00是正确的。但是当我解析0 结果是.00。我该怎么做0.00

注意:我尝试使用String.format扩展,("%.2f",value)但是问题是当它达到10000.0时,它返回10,0000.00。

java string-formatting decimalformat

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