Android Push Notification - Parsing JSON Notification tag name to get raw file (Resource Id or Uri)

345 views Asked by At

I am getting notification from GCM in onMessage() method as intent extraData in json string given below:-

"data": { "message":"Welcome Message","sound_file":"sound1.mp3"}

And I have same file name sound1.mp3 in my res/raw/sound1.mp3 which i need to assign in Notification.Sound. So is there any mechanism by which I can convert String to ResourceId or access the ResourceId through Uri to assign in Notification.Sound.

I want to do this because there will be multiple files and any random sound_file name can come in notification message.

Note:- I can use if else to check sound_file with my files stored in raw folder that i have already implemented. But i just want to know is that can be done what i have asked???

1

There are 1 answers

0
xizzhu On
int resourceId = context.getResources("sound1.mp3", "raw", context.getPackageName());
Uri resourceUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resourceId);