“ACTION_MEDIA_SCANNER_SCAN_FILE:String"已弃用 [英] 'ACTION_MEDIA_SCANNER_SCAN_FILE:String' is deprecated

查看:37
本文介绍了“ACTION_MEDIA_SCANNER_SCAN_FILE:String"已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

activity?.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.fromFile(copyFile)))

我收到警告ACTION_MEDIA_SCANNER_SCAN_FILE 已弃用."在上面的代码中

I got the warning "ACTION_MEDIA_SCANNER_SCAN_FILE is deprecated." in above code

有简单的替换代码吗?

谢谢

推荐答案

ACTION_MEDIA_SCANNER_SCAN_FILE 已弃用!

ACTION_MEDIA_SCANNER_SCAN_FILE Deprecated!

您可以使用以下内容

Java

File file = new File(filePath);
MediaScannerConnection.scanFile(context,
                    new String[]{file.toString()},
                    null, null);

科特林

val file = File(filePath) 
MediaScannerConnection.scanFile(context, arrayOf(file.toString()),
      null, null)

这将请求媒体扫描仪扫描指定路径中的文件.另外,值得注意的是,在上面的例子中,scanFile() 方法中的第三个和第四个参数为空.然而,第三个参数可用于选择性地指定文件的 MIME 类型,第四个参数可用于提供侦听器来侦听扫描完成事件.

This will request the media scanner to scan the files at the specified path. Also, it is worth noticing that 3rd and 4th param in scanFile() method is null in the above example. However the third param can be used to optionally specify the MIME TYPE of the file and the fourth param can be used to supply a listener to listen to the scan completion event.

参考开发者网站了解详情

以下是不推荐使用的方式

Following is the deprecated way

sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));

这篇关于“ACTION_MEDIA_SCANNER_SCAN_FILE:String"已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆