Hello. Thank you for your help.
I've been working on a simple app to send sms to student's parents. So I have to send them rather quickly.
When I send an example message written inside the code, 20 or 30 sms can be sent without trouble. But when I want to pick the telephone number and the message from a text file (or a sqlite table) only 3 or 5 sms arrive to destiny althow LOG shows the app is still runing.
Can this be possible? I tryed many things: working with services, working with sqlite, changing telephone company, waiting up to 60 seconds between sms's, ... and always the same result.
Any idea about what am I doing wrong?
This is my code, now sending an example message, written by hand inside the code. But this is the version where I pick data from text file.
Thanks.
Sergio
I've been working on a simple app to send sms to student's parents. So I have to send them rather quickly.
When I send an example message written inside the code, 20 or 30 sms can be sent without trouble. But when I want to pick the telephone number and the message from a text file (or a sqlite table) only 3 or 5 sms arrive to destiny althow LOG shows the app is still runing.
Can this be possible? I tryed many things: working with services, working with sqlite, changing telephone company, waiting up to 60 seconds between sms's, ... and always the same result.
Any idea about what am I doing wrong?
This is my code, now sending an example message, written by hand inside the code. But this is the version where I pick data from text file.
Thanks.
Sergio
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: POP3 Example
#VersionCode: 2
#VersionName: 1.01
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
Sub Process_Globals
Dim SMS As PhoneSms
Dim PE As PhoneEvents
Dim PhoneID As PhoneId
Dim m As Message
Dim h As Int
Dim wid As Int
Dim wnumero As String
Dim wmensaje As String
Dim wsuccess As Boolean
Dim archivo As String
archivo = "mensajes.txt"
Dim linea As String
Dim numero, mensaje As String
End Sub
Sub Globals
Private Label1 As Label
Private EditText2 As EditText
Private Button1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("Layout1")
If FirstTime Then
End If
insertar
Enviar
End Sub
Sub Activity_Pause(UserClosed As Boolean)
End Sub
Sub Activity_Resume
End Sub
Sub Button1_Click
End Sub
Sub Enviar
PE.InitializeWithPhoneState("PE", PhoneID)
Dim directorio As String
If File.ExternalWritable = True Then
' Si hay SD Card lo leerá de ella
directorio = File.DirRootExternal
Else
' Si no hay SD Card lo leerá del directorio interno
directorio = File.DirInternal
End If
If File.Exists(directorio, archivo) = True Then
Dim leer As TextReader
Dim finalnumero As Int
Dim finallinea As Int
' Lee Línea
leer.Initialize(File.OpenInput(directorio, archivo))
linea = leer.ReadLine
Dim a As Int
Do While linea <> Null
Log(linea)
a = a+1
finalnumero = linea.IndexOf2(":",0)
numero = linea.SubString2(0, finalnumero)
finallinea = linea.Length
mensaje = linea.SubString2(finalnumero+1, finallinea)
'numero = "351599999"
'mensaje = "message written by hand "&wid
' Dim PhoneNumber As String = numero
'Dim Message As String = mensaje
Dim WantSentStatus As Boolean = True
Dim WantDeliveryNotification As Boolean = True
Try
SMS.Send2(numero,mensaje,WantSentStatus,WantDeliveryNotification)
Catch
Log("Error when sending "& LastException.Message)
Log(LastException.Message & CRLF)
End Try
linea = leer.ReadLine
Pausa(20)
Loop
leer.Close
End If
End Sub
Sub PE_SmsDelivered (PhoneNumber As String, Intent As Intent)
'Have never got a receipt from SMS using this!
Dim Result As String
Result="Receipt received Message" & wid
'Log(Result & CRLF)
'EditText1.Text=Result & CRLF
End Sub
Sub PE_SmsSentStatus(Success As Boolean, ErrorMessage As String, PhoneNumber As String, Intent As Intent)
Dim Result As String
Result="SMS Sent Status:" & Success & " : " & ErrorMessage & " " & PhoneNumber
'Log("Success: "&Success)
If Success = True Then
wsuccess = Success
End If
'EditText4.Text = Result & CRLF
'EditText1.Text=EditText1.Text & Result & CRLF
End Sub
Sub insertar
Dim archivo As String
archivo = "mensajes.txt"
Dim linea As String
Dim numero, mensaje As String
Dim directorio As String
If File.ExternalWritable = True Then
' Si hay SD Card lo guarda en ella
directorio = File.DirRootExternal
Else
' Si no hay SD Card lo guarda en directorio interno
directorio = File.DirInternal
End If
File.Delete(directorio,archivo)
Log("archivo borrado")
For i = 1 To 10
Log("insertando linea "&i)
numero = "3515644741"
mensaje = "mensaje en texto tres "&i
linea = numero & ":" & mensaje
Dim escribir As TextWriter
escribir.Initialize(File.OpenOutput(directorio, archivo, True))
escribir.WriteLine(linea)
escribir.Close
Next
End Sub
Sub Pausa(segundos As Long)
Dim now As Long
now = DateTime.Now
Do Until (DateTime.Now > now + (segundos * 1000))
DoEvents
Loop
End Sub