Reputation: 63
History:
I download Ringtone from web server, if SD card is mounted i saved that file to SD Card path like, mnt/sdcard/.my_folder_name/abc.mp3 ELSE saved to internal memory using context.getFilesDir() like, data/data/my.package.name/abc.mp3
PROBLEM:
I'm firing Android Notification in Notification Bar, Notification is working fine but the problem occurs when i set NOTIFICATION SOUND URI from internal memory, it Doesn't play sound.
IN CASE OF EXTERNAL STORAGE, WORKS FINE and SOUNDS PLAYS
ringtoneUri = Uri.parse("file:///mnt/sdcard/.my_folder_name/abc.mp3");
notification.sound = ringtoneUri;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
notificationManager.notify(1, notification);
IN CASE OF INTERNAL STORAGE, DOESn't Play SOUNDS PLAYS i checked the file, it exists there
ringtoneUri = Uri.parse(context.getFilesDir().getPath()+"/abc.mp3");
// data/data/my.package.name/files/abc.mp3
notification.sound = ringtoneUri;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
notificationManager.notify(1, notification);
Am i Doing something Wrong???
Regards,
Upvotes: 2
Views: 1365
Reputation: 63
The problem is that, Internal Storage is not supported to Use by NOTIFICATIONS. You need to add public permission to that Audio File.
File file = new File(context.getFilesDir().getPath()+"/abc.mp3");
file.setReadable(true, false);
ringtoneUri = Uri.parse(context.getFilesDir().getPath()+"/abc.mp3");
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;
notificationManager.notify(1, notification);
...
Thanks
Salik
Upvotes: 4
Reputation: 16832
I would check permissions. Each application is a user. Do all users have the right to read the file (and probably the enclosing folder[s])?
Upvotes: 0