Android Question Change volume ringtone

AHilberink

Active Member
Licensed User
Longtime User
Hi,

I am using:
B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim rt,jo, jo2 As JavaObject
    Dim u As Uri
    Dim rm As RingtoneManager
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    rt = getRingtone
    Activity.LoadLayout("ringtone")
    PlayRingtone
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub getRingtone As JavaObject
    jo.InitializeStatic("android.media.RingtoneManager")
    jo2.InitializeContext
    Dim u As Uri
    u.Parse(rm.GetDefault(rm.TYPE_ALARM))
    'u.Parse()
    Dim rt As JavaObject
    rt.InitializeContext
    rt = jo.RunMethodJO("getRingtone", Array(jo2, u))
    Return rt
End Sub

Sub PlayRingtone
    rt.RunMethod("play", Null)
End Sub

Sub StopRingtone
    rt.RunMethod("stop", Null)
End Sub

Sub Stopmelding_Click
    StopRingtone
    Activity.Finish
End Sub

to play ringtone.

Is there a way to set the volume?

Best regards,
André
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The documentation example code is incorrect. I've updated it.
The correct code is:
B4X:
 Sub Process_Globals
     Private rm As RingtoneManager
 End Sub
 Sub Globals
 End Sub
 Sub Activity_Create(FirstTime As Boolean)
     rm.ShowRingtonePicker("rm", rm.TYPE_RINGTONE, True, "")
 End Sub
 Sub rm_PickerResult (Success As Boolean, Uri As String)
     If Success Then
         If Uri = "" Then
             ToastMessageShow("Silent was chosen", True)
         Else
             rm.Play(Uri)
         End If
     Else
         ToastMessageShow("Error loading ringtone.", True)
     End If   
 End Sub

You can change the volume of the relevant channel:
B4X:
 Sub Activity_Click
   Dim p As Phone
   p.SetVolume(p.VOLUME_RING, p.GetMaxVolume(p.VOLUME_RING), False)
 End Sub
 
Upvote 0
Top