本文介绍了不推荐使用"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

有一个简单的替换代码吗?

Is there a simple replacement 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()},
                    new String[]{file.getName()},null);

科特林

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

这将要求媒体扫描仪扫描指定路径下的文件.

This will request the media scanner to scan the files at the specified path.

有关详情,请参阅开发者网站

以下是不推荐使用的方式

Following is the deprecated way

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

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

09-26 06:51