I am creating an own application for android that generates playlists. Application creates .m3u files in UTF-8 encoding format. Files exist and visible in file manager, but media players don't see the playlists and this is a problem. Playlists files are correct and work properly in build-in player in file manager. Here is some part of the code, that gererates playlists:
File file = new File(Environment.getExternalStorageDirectory() + "/Music","Test.m3u");
PrintWriter writer = new PrintWriter(file, "UTF-8");
...
writer.println(PathToSong.toString()+"\r");
....
writer.flush();
writer.close();
I downloaded a program from Play Market that also creates playlists (.m3u) files. Playlists files that are built by the program have the same format as mine, but visible for media players. The most interesting thing is: ater launch the program from Play Market, playlists from my own program becomes visible for media players too.
Also my playlists become visible for the media players after restarting the phone. I develop and test my application using Android Studio 0.3.4.
I found the answer. It is needed to run media scanner so that mediafiles(photo, music, etc.) become visible in applications. Media Scanner runs automatically after phone restart. To run Media Scanner manually you just need to paste and run this part of code:
UpdateMediaIntent = new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()));
sendBroadcast(UpdateMediaIntent);
Hope, it will be helpful for somebody else too.