Android Question granturipermission error on internal storage in NB6 customSound

Azam Memon

Member
Licensed User
I have obtained URI of a sound using RingTone Manager for NB6 custom sound, the URI of sound is:

B4X:
content://media/internal/audio/media/30
When I try

B4X:
n.CustomSound("content://media/internal/audio/media/30")
I get the following exception.

B4X:
(RuntimeException) java.lang.RuntimeException: Method: grantUriPermission not matched.
and when I try to use:

B4X:
Dim u As Uri
u.Parse("content://media/internal/audio/media/30")
n.CustomSound(u)
I do not get any Exception but it also plays default sound, instead of the selected one.

however, the same URI works fine with RingtoneManager and plays the sound. Please suggest any workaround for this issue.

Thanks
 

Erel

Administrator
Staff member
Licensed User
and when I try to use:

B4X:
Dim u As Uri
u.Parse("content://media/internal/audio/media/30")
n.CustomSound(u)
This looks correct. Try to change the channel id. Once you plan a notification with a specific channel id the sound cannot be changed.
 

wes58

Active Member
Licensed User
So do I need to change channel id every time the user changes notification sound?
No, you don't have to, if the user changes the sound on the application notification settings screen. That what is behind google's idea with notification channels. Once you create the channel with specific settings, only the user can change those settings - i.e. change the sound, change vibration or change whether they want to have notification enabled or not. You should respect user's choice of notification sound.You should use the same channel id.
 

Azam Memon

Member
Licensed User
Once you create the channel with specific settings, only the user can change those settings - i.e. change the sound, change vibration or change whether they want to have notification enabled or not.
How a user can change these settings? I don't want to change message tone for all applications, all i want is to change sound of notification for my own application.

The only way to do it is to set notification sound as:

B4X:
Dim u As Uri
u.Parse("content://media/internal/audio/media/30")
n.CustomSound(u)
Where n is NB6

And when I set a specific channel id and a specific sound, then even if I change the sound with keeping same channel id, sound of notification doesn't change.

Can you please suggest workaround for that? With example code?
 

wes58

Active Member
Licensed User
How a user can change these settings? I don't want to change message tone for all applications, all i want is to change sound of notification for my own application.

The only way to do it is to set notification sound as:



Where n is NB6

And when I set a specific channel id and a specific sound, then even if I change the sound with keeping same channel id, sound of notification doesn't change.

Can you please suggest workaround for that? With example code?
Have a look in this thread https://www.b4x.com/android/forum/threads/nb6-class-additional-functions.104319/
 
Top