Music Files not getting visible in Google Play music

557 Views Asked by At

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.

3

There are 3 best solutions below

3
Arpit On BEST ANSWER

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.

5
lelloman On

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

0
Joshua Kan On

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