1

I am developing an app that is used to download the songs. I am able to download the songs and as the download is completed I am moving that song to a different folder programmatically.

The issue that I am facing is that if I am moving song to another folder it does not become visible in google play Music and if I do not move it to another folder it is visible in Google Play Music but if the song is not moved it is getting deleted once the app is uninstalled. Please help me out what can be done to resolve this. I am stuck in this functionality.

Thanks.

Arpit
  • 604
  • 5
  • 17

3 Answers3

1

you need to can call MediaScannerConnection.scanFile() after you've copied the new file and PlayMusic app will see it

MediaScannerConnection.scanFile(context, new String[]{absolutePathToTheNewFile}, null, new MediaScannerConnection.OnScanCompletedListener() {
    public void onScanCompleted(String path, Uri uri) {

    }

});

according to official docs, the Uri passed in onScanCompleted(String, Uri) will be null if the scan had failed

lelloman
  • 13,883
  • 5
  • 63
  • 85
  • Thanks for the reply lelloman. Please let me know what is "mysong.mp3" and what is "copy.mp3". I moved the file from one location to another, I have path for both the location and the name of file. What should I do now ? – Arpit Feb 28 '17 at 05:09
  • that's just an example, the important thing is MediaScannerConnection.scanFIle, you need to call that one and instead where file.getAbsolutePath() is your new file path – lelloman Feb 28 '17 at 06:08
  • Thanks man, but I think MediaScannerConnection is not allowed in BroadcastReceiver. – Arpit Feb 28 '17 at 10:07
  • what do you mean? – lelloman Feb 28 '17 at 10:31
  • I am using a BroadcastReceiver to check once the download is completed and in that I am using MediaScannerConnection. But after running code I am getting an exception. – Arpit Feb 28 '17 at 11:16
1

After searching for 3 days. I finally got the solution to this.

    Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
    intent.setData(Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/FolderName/"+inputFile)));
    context.sendBroadcast(intent);

I am sending broadcast to the default Google Music Library once the downloading and moving is completed.

Arpit
  • 604
  • 5
  • 17
  • I am facing similar problem as you were, I have tried adding your code to onPostExecute() method for my app, but it is still not being recognized, how can I fix this ? – CaptainDaVinci Jun 29 '17 at 07:25
  • You are not able to see the downloaded song in the Google play music after adding the above code ? – Arpit Jul 03 '17 at 11:19
  • Unfortunately no, I managed to fix the problem by using download manager instead. – CaptainDaVinci Jul 03 '17 at 13:43
0

Is your new folder on the SD card? Because Google Play Music app can only see songs inside Internal Storage, not SD card.

Joshua Kan
  • 353
  • 2
  • 7