Android Question Sending a Text every 15 min

PCowling

Member
Licensed User
Longtime User
Hi

I have an app that generates a text message and sends it. However I want this to happen every 15 minutes, even if the program is not the focus.

I have looked through the tutorials but I am struggling with them, are there any recommendations or help I could have please?

Thanks
 
G

GCOINC

Guest
I have a timer when fires resets to a random 'wait' time, this (timer and SendSMS) can be stuffed in a service if required. FYI most providers have a 100 msg/per hr max, thus my timer fires in intervals not exceeding the provider limit and not throwing a 'flag' to the provider.

B4X:
Sub Timer1_Tick()
    Dim PhoneNumber As String
    Dim SMSMessage As String
 
    PhoneNumber = (PhoneNumContent.Text)
    SMSMessage = (TextMsgContent.Text)

    SendSms(PhoneNumber, SMSMessage)

    Timer1.Interval = Rnd(46000,72000)

B4X:
Sub SendSms(PhoneNumber As String, Text As String)
    Dim ps As PhoneSms
    Dim r As Reflector
    r.Target = r.RunStaticMethod("android.telephony.SmsManager", "getDefault", Null, Null)
    r.RunMethod4("sendTextMessage", Array As Object(PhoneNumber, Null, Text, Null, Null), _
        Array As String("java.lang.String", "java.lang.String", "java.lang.String", _
            "android.app.PendingIntent", "android.app.PendingIntent"))
          
End Sub
 
Upvote 0
Top