这几天我在做这个...
我的应用程序会自行删除某些文件。但是当我通过MTP模式将手机与PC连接时,已删除的文件仍然“活着”,但无法复制或打开。
我知道事实上这些文件已经被删除了,但我必须刷新 MTP。我尝试了以下方法:
MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null);
但它不起作用......
这里有人知道如何解决这个问题吗?谢谢!
删除文件时,在删除调用触发后调用 refreshSystemMediaScanDataBase() 方法刷新媒体
/**
@param context : it is the reference where this method get called
@param docPath : absolute path of file for which broadcast will be send to refresh media database
**/
public static void refreshSystemMediaScanDataBase(Context context, String docPath){
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
Uri contentUri = Uri.fromFile(new File(docPath));
mediaScanIntent.setData(contentUri);
context.sendBroadcast(mediaScanIntent);
}