在媒体文件改变后 发出 Intent.ACTION_MEDIA_SCANNER_SCAN_FILE广播,告知其余应用,媒体文件发生改变。测试
具体代码片断:spa
1 File oldFile = new File(oldPath); 2 File newFile = new File(newPath); 3 if (oldFile.exists() && !newFile.exists()) { 4 if (oldFile.renameTo(newFile)) { 5 6 Uri fileUri = Uri.fromFile(newFile); 7 Intent intent = new Intent(); 8 intent.setAction(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); 9 intent.setData(fileUri); 10 sendBroadcast(intent); 11 } 12 }
通过测试上面的代码在三星,联想的手机上很差用code
通过试验 将面代码的 6- 10 行换成下面的代码就好用了blog
sendBroadcast(newIntent(Intent.ACTION_MEDIA_MOUNTED,Uri.parse("file://"+Environment.getExternalStorageDirectory())));