Spanish Problema Atavoz Interno Android 8

Jannete

Member
Hola a todos, hace tiempo hice una apicacion (motivos autodidacticos) que emula una llamada (usa TTS para la voz que esta hablando como si fuera contestadora). En Kit Kat funciona perfecto, pero al intentar en Android 8 no hace nada. Dejo el codigo que estoy usando, haber si alguien sabe algo. Muchas gracias por adelantado.

B4X:
Sub Process_Globals
    Dim altavoz As Boolean = False
    Dim TTS1 As TTS
    Dim mp As MediaPlayer
    
    Dim duracion As Timer
End Sub

Sub Globals
    Private bLoud As Button
    'Private bCall As Button
    Private bColgar As Button
    
    Private pMask As Panel
    
    Dim ps As PhoneSensors
    Dim pw As PhoneWakeState
    
        
    Private lAltavoz As Label
    Private lNumero As Label
    Private lNumero2 As Label
    Private lTiempo As Label
    Private lTiempoFin As Label
    Private pFinal As Panel
    
    Dim segundo As Int = 0
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    
    If FirstTime Then
        ps.Initialize(ps.TYPE_PROXIMITY)
        ps.StartListening("ps")
    End If
End Sub

Sub Activity_Resume
    SetEarPhone(True)
'    setSpeakerPhone(True)

    pw.KeepAlive(True)
    pw.PartialLock
            
    lNumero.Text = sos.LlamarA
    lNumero2.Text = sos.LlamarA
    
    TTS1.Initialize("TTS1")
    mp.Initialize2("mp")
                
    LlamadaF
End Sub

Sub Activity_Pause(UserClosed As Boolean)
    SetEarPhone(False)
'    setSpeakerPhone(False)
'    If TTS1.IsInitialized Then TTS1.Stop
'    If mp.IsPlaying Then mp.Stop
    
    TTS1.Release
    mp.Release
    
    pw.ReleaseKeepAlive
    pw.ReleasePartialLock
    
    If duracion.IsInitialized Then duracion.Enabled = False
End Sub

Sub TTS1_Ready (Success As Boolean)
    If Success Then
        Log("TTS Iniciado")
    Else
        MsgboxAsync("Error al iniciar texto a voz", "Error")
        Wait For Msgbox_Result (Result As Int)
        If Result = DialogResponse.POSITIVE Then
            '
        End If
    End If
End Sub

Sub ps_SensorChanged (Values() As Float)
    Log(Values(0))
    If Values(0) = 3 Then '3 = Sensor tapado, 100 = Sensor destapado
        pMask.Visible = True
        pMask.Enabled = True
    Else
        pMask.Visible = False
        pMask.Enabled = False
    End If
End Sub

'
Sub SetEarPhone(Value As Boolean)
    'Private Sub setSpeakerPhone(value As Boolean)
    
    'Invetir
    If Value = True Then
        Value = False
    Else
        Value = True
    End If
    
            
    Dim ctxt As JavaObject
    ctxt.InitializeContext

    Dim audioManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array(ctxt.GetField("AUDIO_SERVICE")))
    Dim audioManagerStatic As JavaObject
    audioManagerStatic.InitializeStatic("android.media.AudioManager")
  
    Dim originalMode As Int = audioManager.RunMethod("getMode",Null)
  
    If Value Then
        audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_IN_CALL")))
    Else
        audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_NORMAL")))
    End If
  
    audioManager.RunMethod("setSpeakerphoneOn", Array(Value))
    ' // restore original mode
    audioManager.RunMethod("setMode", Array(originalMode))
  
  
End Sub
'
'Sub SetEarPhone(Value As Boolean)
'    Dim r As Reflector
'   
'    r.Target = r.GetContext
'    r.Target = r.RunMethod2("getSystemService", "audio", "java.lang.String")
'   
'    Dim mode As Int
'   
'    If Value Then mode = 2 Else mode = 0
'   
'    r.RunMethod2("setMode", mode, "java.lang.int")
'   
'    If Value = True Then
'        altavoz = False
'        lAltavoz.Visible = False
'        LogColor("Altavoz Desactivado", Colors.Green)
'    Else
'        altavoz = True
'        lAltavoz.Visible = True
'        LogColor("Altavoz Activado", Colors.Red)
'    End If
'End Sub

Sub pMask_Click
    Return
End Sub

Sub bColgar_Click
    Colgar
End Sub

Sub LlamadaF
    'Sleep(2000)
        
    Log("Play")
    
    mp.Load(File.DirAssets, "llamada.mp3")
    mp.Play
End Sub

Sub mp_Complete
    Log("Completado mp3")
    
    lTiempo.Text = "00:00"
    lTiempoFin.Text = "00:00"
    
    Dim bd As BitmapDrawable
    
    bd.Initialize(LoadBitmap(File.DirAssets, "encurso.jpg"))
    bd.Gravity = Gravity.FILL
    Activity.Background = bd
    
'    Dim bp As Bitmap
'   
'    bp.Initialize(File.DirAssets, "encurso.jpg")
'   
'    Activity.SetBackgroundImage(bp)
    
    duracion.Initialize("tmr", 1000)
    duracion.Enabled = True
    
    Hablar
End Sub

Sub Hablar       
    Log("Habla")
    
    TTS1.Speak("Esta hablando al telefono de tal", False)
    
    Dim jo As JavaObject
    
    Dim jo As JavaObject = TTS1
    
    Do While jo.RunMethod("isSpeaking",Null) = True
        Sleep(100)
    Loop
    
    Log("Fin llamada")
    SetEarPhone(True)
    Colgar
End Sub

Sub tmr_Tick
    segundo = segundo + 1
        
    Dim SegundosExactos As String = segundo
    
    If SegundosExactos.Length = 1 Then SegundosExactos = "0" & SegundosExactos
    
    lTiempo.Text = "00:" & SegundosExactos
End Sub

Sub bLoud_Click
    If altavoz Then
        SetEarPhone(True)
        'setSpeakerPhone(True)
    Else
        SetEarPhone(False)
        'setSpeakerPhone(False)
    End If
End Sub

Sub Colgar
    pFinal.Enabled = True
    duracion.Enabled = False
    
    Dim SegundosExactos As String = segundo
    
    If SegundosExactos.Length = 1 Then SegundosExactos = "0" & SegundosExactos
    lTiempoFin.Text = "Tiempo de Llamada 00:" & SegundosExactos   
    
    pFinal.Visible = True
            
    TTS1.Release
    mp.Release
    
    SetEarPhone(False)
'    setSpeakerPhone(False)
'    If TTS1.IsInitialized Then TTS1.Stop
'    If mp.IsPlaying Then mp.Stop
    
    Log("Va a colgar")
    
    pw.ReleaseKeepAlive
    pw.ReleasePartialLock
    
    Sleep(1000)
    
    sos.Primero = False
    Activity.Finish
End Sub

'Private Sub setSpeakerPhone(value As Boolean)
'
'    Dim ctxt As JavaObject
'    ctxt.InitializeContext
'
'    Dim audioManager As JavaObject = ctxt.RunMethodJO("getSystemService", Array(ctxt.GetField("AUDIO_SERVICE")))
'    Dim audioManagerStatic As JavaObject
'   
'    audioManagerStatic.InitializeStatic("android.media.AudioManager")
'   
''    Dim originalMode As Int = audioManager.RunMethod("getMode",Null)
'   
'    If value Then
'        altavoz = False
'        bLoud.TextColor = Colors.Green
'        LogColor("Desactivado", Colors.Green)
'        audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_IN_CALL")))
'    Else
'        altavoz = True
'        bLoud.TextColor = Colors.Red
'        LogColor("Activado", Colors.Red)
'        audioManager.RunMethod("setMode", Array(audioManagerStatic.GetField("MODE_NORMAL")))
'    End If
'   
''    audioManager.RunMethod("setSpeakerphoneOn", Array(value))
'    ' // restore original mode
''    audioManager.RunMethod("setMode", Array(originalMode))
'   
'   
'End Sub

Sub pFinal_Click
    Return
End Sub
 
Top