1

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???

TommySM
  • 3,793
  • 3
  • 24
  • 36
  • Anyone help me please –  Jun 09 '15 at 08:04
  • for String to Uri : [this SO question](http://stackoverflow.com/questions/3487389/convert-string-to-uri) – TommySM Jun 09 '15 at 08:36
  • Uri of RecsourceID not String to Uri –  Jun 09 '15 at 09:07
  • then look at this [SO question](http://stackoverflow.com/questions/4896223/how-to-get-an-uri-of-an-image-resource-in-android) , I think the combination might do the trick. – TommySM Jun 09 '15 at 09:09

1 Answers1

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