Recently to be the camera. After the system to save the photos to the album. Always use sendBroadcast to inform ACTION_MEDIA_SCANNER_SCAN_FILE invalid.
Code is as follows:
String url = MediaStore.Images.Media.insertImage (getContentResolver (), picture, "", "");
Uri uri = Uri.parse (url);
sendBroadcast (new Intent (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
Found that the system did not always update the album!
Device is HTC G18, we seek guidance under<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
http://blog.csdn.net/vary25/article/details/6278285
Reply:
Try this, it should be so that
/ / 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);
}
});
I wish you success!
Reply:
Uri data = Uri.parse ("file :/ /" + "Here is a picture of the path");
sendBroadcast (new Intent (Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, data));
Reply:
Note: Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, is only scanned documents, does not scan the folder, you have to find the specified file
private void scanSdCard () {
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
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 ());
}
}
}
}
No comments:
Post a Comment