Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Android™ Runtime Development

Reply
New Contributor
Posts: 2
Registered: ‎06-21-2013
My Device: Developer
My Carrier: Developer
Accepted Solution

Notification Sound

Is is possible for an App to set its own notification sound by setting an Uri to a raw resource file in Notification.sound?

 

It does not seem to be working for me, perhaps there are some file permission declarations I need to do or somehow get the file to a shared directory?

 

Any help would be much appreciated, thank you.

New Contributor
Posts: 9
Registered: ‎04-29-2013
My Device: Z10
My Carrier: Verizon

Re: Notification Sound

Finally! Someone else with this issue.

 

I am having the exact same problem. I am trying to set the Notification.sound property using a raw URI.

 

notification.sound = Uri.parse("android.resource://" + getPackageName() + "/" + toneResourceID);
notification.audioStreamType = AudioManager.STREAM_NOTIFICATION;

 This works perfectly fine on all versions of Android but I get the default BB10 notification when I port the Android app over to BB10. I have tried a number of things and nothing seems to affect it.

 

Could it be that we need to set the Notification.sound property in a different, more compatible way? Anyone else seeing this on their converted Android app in BB10 or can confirm that this truly is a known issue??

 

New Contributor
Posts: 2
Registered: ‎06-21-2013
My Device: Developer
My Carrier: Developer

Re: Notification Sound

I have a feeling this is a sandbox/permissions issue where audio file is not publically available for the Notification Center to play.

 

As a workaround, what I did was 

 

1) Silence the Notification sound by not setting notification.sound

2) Play the audio file from the app using MediaPlayer. This happens asynchrously as I perform the notification.

 

Everything seems to happen in sync and looks right from the end user's point of view. Things may look off if there are multiple notifications happening at the same time but this is the best solution I could come up with for now.

New Contributor
Posts: 9
Registered: ‎04-29-2013
My Device: Z10
My Carrier: Verizon

Re: Notification Sound

Thanks! Your workaround mostly did the trick! 

 

I had a similar idea and it did not work because I did not unset the Notification.sound property. Once I did that, it worked pretty well. Sometimes it cuts the sound off before it has a chance to play fully. Sometimes it will play 98% of it. I continue to investigate this issue. Please let me know if you have any ideas regarding this. 

 

Thanks again!

Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Notification Sound

My goal is to property support this in 10.2. You're right, we were attempting to set a sound that the notifications service could play, but it couldn't access it. It'd probably work if your notification was located on the sdcard or internet public storage or something.

Either way, the goal in 10.2 is to have the runtime do as you're doing right now Smiley Happy