Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've been trying to create a simple MP3 downloader for Android. All it does is connect to the URL, downloads the track and guesses the ID3 information based on the name. The problem with my application is that once a song is downloaded, it does not instantly show up in the Google Music app, nor in the default music player application. I even tried some other ones without luck, they all do not reindex it.

The only thing I noticed was that when I copied/moved the song from the Music folder on my SD card to the root of the SD card, it reindexed the entire library properly. This gave me the idea that it might not be alerting any file listeners.

My question is: how would I be able to save a song to the Music folder, and having the music players update their indices? Thank you in advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
489 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to notify the MediaScanner that a new file has been added and should be indexed so it shows up in the MediaStore.

The simplest way is to send a broadcast once the file has been downloaded:

Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
intent.setData(Uri.fromFile(file));
sendBroadcast(intent);

http://developer.android.com/reference/android/content/Intent.html#ACTION_MEDIA_SCANNER_SCAN_FILE

The assumes the "other music players" use the MediaStore, but it's a good bet that they do.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...