使用KitKat中提供的SAF,MediaScanner不会调用保存到设备内部或外部存储点的文件。因此,我必须根据返回的URI确定是否应该尝试运行MediaScanner。存储访问框架不更新MediaScanner(MTP)
// The SAF uses content URI to pass meta about the file. The following host is used for internal storage.
if (mExportServiceUri.getHost().equals("com.android.externalstorage.documents")) {
final File externalStorage = Environment.getExternalStorageDirectory();
final String path = mExportServiceUri.getEncodedPath().replace("/document/primary%3A", "");
MediaScannerConnection.scanFile(mService.getApplicationContext(), new String[] { new File(
externalStorage, path).getAbsolutePath() }, null, null);
}
有没有其他人必须解决这个问题,如果是的话,有没有比这更好的方法?目前这仅支持设备外部存储,并且额外的存储空间(如SD卡)需要在单独的支票中处理。
我相信这可以解决我的问题,但我担心它可能无法在所有设备上继续使用,甚至无法正常工作。我仍然乐于接受更好的MediaScanner处理建议。 –