Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Android应用程序中删除文件,但该文件仍存在于MTP中_Android_Mtp - Fatal编程技术网

在Android应用程序中删除文件,但该文件仍存在于MTP中

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

这几天我在做这个

我的应用程序自己删除一些文件。但是,当我通过MTP模式将手机与PC连接时,已删除的文件仍处于“活动”状态,但无法复制或打开

我知道实际上文件已经被删除了,但我必须刷新MTP。我尝试过以下方法:

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);
}