解决方案 »
- 如何解决: E/AndroidRuntime(1459): java.lang.ArrayIndexOutOfBoundsExcep
- android应用。求高手解答
- android 运行慢
- Android如何适配不同品牌的手机呢?需要移植吗?
- 怎么在XML文件中把背景设置为透明的??
- Android在线音乐搜索实现方案
- 超长短信 ,接收如何自动合并成一条
- could not find folder tools inside sdk
- 关于android socket输入流与readLine()
- 关于线程里的toast,我有点迷糊,请指教!
- 4.2.2蓝牙A2DP连接
- PC与Android的UDP通信
// Tell the media scanner about the new file so that it is
// immediately available to the user.
MediaScannerConnection.scanFile(this,
new String[] { file.toString() }, null,
new MediaScannerConnection.OnScanCompletedListener() {
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned " + path + ":");
Log.i("ExternalStorage", "-> uri=" + uri);
}
});
祝你成功!
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
String file= Environment.getExternalStorageDirectory().getAbsolutePath()+"/Photo";
folderScan(file);
}
private void fileScan(String file){
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.parse("file://" + file)));
}
private void folderScan(String path){
File file = new File(path);
if(file.exists() && file.isDirectory()){
File[] array = file.listFiles();
for(int i=0;i<array.length;i++){
File f = array[i];
if(f.isFile()){//FILE TYPE
String name = f.getName();
if(name.endsWith(".mp4") || name.endsWith(".mp3") || name.endsWith(".jpg")){
fileScan(f.getAbsolutePath());
}
}
else {//FOLDER TYPE
folderScan(f.getAbsolutePath());
}
}
}
}