在Android应用程序中删除文件,但该文件仍存在于MTP中
这几天我在做这个 我的应用程序自己删除一些文件。但是,当我通过MTP模式将手机与PC连接时,已删除的文件仍处于“活动”状态,但无法复制或打开 我知道实际上文件已经被删除了,但我必须刷新MTP。我尝试过以下方法:在Android应用程序中删除文件,但该文件仍存在于MTP中,android,mtp,Android,Mtp,这几天我在做这个 我的应用程序自己删除一些文件。但是,当我通过MTP模式将手机与PC连接时,已删除的文件仍处于“活动”状态,但无法复制或打开 我知道实际上文件已经被删除了,但我必须刷新MTP。我尝试过以下方法: MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null); 但它不起作用 这里有人知道如何解决这个问题吗?谢谢 删除文件时,在delete调用触发器之后调用refreshSystemMedia
MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null);
但它不起作用
这里有人知道如何解决这个问题吗?谢谢 删除文件时,在delete调用触发器之后调用refreshSystemMediaScandabase()方法来刷新媒体
/**
@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);
}
删除文件时,在delete调用触发器后立即调用RefreshSystemMediaScandabase()方法以刷新媒体
/**
@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);
}