【问题标题】:Delete a file in Android APP, but the file is still exist in MTP删除Android APP中的文件,但该文件仍然存在于MTP中
【发布时间】:2016-03-17 11:47:25
【问题描述】:

这些天我正在努力解决这个问题......

我的应用程序会自行删除某些文件。但是当我通过MTP模式将手机与PC连接时,已删除的文件仍然“活着”,但无法复制或打开。

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

MediaScannerConnection.scanFile(getApplicationContext(), paths, null, null);

但它不起作用......

这里有人知道如何解决这个问题吗?谢谢!

【问题讨论】:

    标签: android mtp


    【解决方案1】:

    删除文件时,在删除调用触发后调用 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      相关资源
      最近更新 更多