Android Question sms interceptor , repeating message_received ?

hookshy

Well-Known Member
Licensed User
Longtime User
I found that sometimes the message_received sub is repeating itself or there is the problem someplace else and I do not know where . The fact is that i send a sms and the code below speaks the body message 3 times in a row?
Strage but yet must be explanation ?:confused:

B4X:
 Sub Process_Globals
dim hsmes as smsinterceptor
end sub


Sub Service_Create
hsmes.Initialize2("hsmes",999)
end sub

B4X:
Sub hsmes_MessageReceived (From As String, Body As String) As Boolean

Try
If Main.cid Then

    If parse_blac.stopsms(From) Then
        Log("mesajul a fost blocat")
        Return True
    End If

End If 'end main.cid

Catch
log_generator("sms_received0")
End Try
'***********************************************

Try

wait.Enabled=True
busy=True
asteapta.Enabled=True
Main.news=True ' anunta mesaj nou


Dim fromtemp As String
fromtemp="Id= , ThreadId= , Personid= , Date="&DateTime.Now&", Read= , Type=, Body="& Body &", Address="&From

'newmes.Add(fromtemp) ' creaaza lista

If IsPaused(Main)=True Then 'daca nu lucrez la ceva       
    Main.telefon=From
    CallSubDelayed(Main,"destinatar") 'copiaza contactul
           
Else ' citeste mesajele si goleste lista de mesaje
   
    If car OR carmode=1 Then
        Main.telefon=From
        CallSubDelayed(Main,"destinatar")   
    End If
   
End If

Catch
log_generator("sms_received1")
End Try





'************************************************************
Try
If Main.citire AND Main.TTS1.IsInitialized Then 'AND stopcit=False Then '?hs

    If Main.cid=True  AND parse_blac.stopread(From) Then
    'daca sunt active blocarile si from se gaseste in blac list
    'nu citeste nimic   
    Log("bloc read sms")
    'donothing
   
    Else
   
        If Main.tech.GetContactNamebyPhone(From).Length>0 Then 'daca contactul este regasit in agenda
           
            If astbol=False Then'delay citire mesaj lung
                astbol=True
                Main.TTS1.speak("Mesaje noi  ",False)
                Main.TTS1.speak(Main.tech.GetContactNamebyPhone(From),False)
                Log("mesaje noi")
            End If

            If carmode=1 Then ' DACA ON ATUNCI CITESTE TOT TIMPUL CONTINUTUL MESAJULUI
                    Main.TTS1.speak(Body,False)
            Else If car AND carmode <> 2 Then ' daca sunt pe auto iar car este true
                    Main.TTS1.speak(Body,False)   
            End If
           
        Else 'daca nu este regasit in agenda
       
            If astbol=False Then
                astbol=True
                Main.TTS1.speak("Mesaj nou",False)
            End If
       
        End If 'end of contact gasit in agenda
       
    End If 'end of blocari


End If 'main.citire si tts initialised
   
   
Catch
log_generator("sms_received2")
End Try
End Sub
 

hookshy

Well-Known Member
Licensed User
Longtime User
As I was testing multiple application that handle that intercept sms messages it may conflict with mine ...
All though if someone was faceing the same problem and found out why please tell
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Found that sms_interceptor works just fine.
Problem is with the initialisation of TTS ...
It some members can eplain this issue ..a guy asked if it is posible to speak while in a call ... Response ..yes with faulty intitialisation of TTS .
I have a service that reads received sms.
On app exit i use:
CancelScheduledService(hsman)'??
StopService(hsman)
Activity.Finish
On app opening another instance of TTS is initialised, Strange thing is that only on sub sms_message_received the text is spoken 2,3,4 times in a roll.
If TTS instance is initialising more times why does not speak 2,3,4 times in activity on buton click or other event of speaking text ?

I do not know when to use the tts.destroy function ?
As the service reads sms in background i do not need to destroy tts if main activity is not on front !

Temporaraly i solved by calling just activity.finish and not destroying the service .

May be here i am doing worg : I use the below statement in process create:
If Main.TTS1.IsInitialized=False Then
Main.TTS1.Initialize("TTS1")
Log("service hsman started tts1")
End If

Statement from main activity
If FirstTime AND TTS1.IsInitialized=False Then
TTS1.Initialize("TTS1")
Log("activity initialised tts1")
End If

thanks for helping!
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
Hi,
I have the same problem. I receive one message, but MessageReceived sub is called 2-3 times.
I use it in a Service Modul. But this dont happen always. Only when the app is running a while


In the SMS message app of the phone the message is only 1 time.

Sub Process_Globals
Dim SI As SmsInterceptor
dim GL_counter as long

Sub Service_Create
SI.Initialize2("SI", 999)

Sub SI_MessageReceived (From As String, Body As String) As Boolean
GL_counter = GL_counter + 1
log(GL_counter)
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
It may happen that the smsinterceptor is not release on time when the app is killed and maybe it is initialised twice ....
I had this problem with tts if you initialise twice the service it will speak the message several time ...

I hope Erel will think about this ...
I did not found any more this problem but i am worried about it ...
there are things on priority and dealing the intents that are over my powers ... but I think I will find it one day
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
sometimes it is very hard because of the communication between the one that created the code and those using it ....
many times I found myself unsing uproperly a function code just because I did not used it corectly ... (for example dealing with notification you must
ensure that the order statements are right otherwise it will fail to do the expected thing) ... dealing with resources is even harder that sometimes in
the code circumstances you must release the resorurces ...
many times I found myself using the release of the resource just before the initialize sequence and I can not tell you why .
 
Upvote 0

gz7tnn

Member
Licensed User
Longtime User
Interesting... I created an app over a year ago that uses a service to respond to sms messages and it worked fine for me. I recently upgraded my phone and now I am experiencing the exact same problem. When I was testing it initially with the old phone, I also had a colleague test for me and he experienced the same thing - multiple replies were being generated, and the app crashed. I was unable to trace anything at that stage so sort of gave up.
So I have relivened my old phone and it appears to still function successfully, though I have no credit so no responses were sent out - but it did not crash the app..

My wife has also upgraded her phone, so I have just installed it on hers now with the same result - multiple replies and both phones 'crash' the app ungracefully.

Delving into into it a bit I wonder if it is related to the OS version.
My original phone, and another one I used as well, are 2.3.6 and 2.3.3
My new phone is a Sony running 4.4.4
My wifes is a Samsung running 4.4.2
The person that tested it in June 2014 had a Nexus 5 with what he described as the latest latest version of Android
My app uses phone 2.1

Hopes that gives someone a clue.
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Unfortunately I could not reproduce the error , problem does not seems to be related to android version
now I use the latest phone lib 2.26 but yet I do not know if any important changes were done to phone lib .

I am blind as long as I do not do java.
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
Just a guess: Could it be that it is a long SMS? There is a limit to the length an SMS can have (160 characters, iirc). Modern devices simply hide that by cutting the message into several SMS messages, or, if it gets even longer, into an MMS. Could it be that you get a call for each part?
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
Good idea,
It happen in my case with messages about 85 characters. I have a new cel. with 4.4.4
Maybe a international character short the limit to 70 characters and the received sub is called
several time.
But, the body text is always the same. Maybe an error in the lib ?
 
Upvote 0

Troberg

Well-Known Member
Licensed User
Longtime User
Perhaps. Should be easy enough to test, just send a short message, such as "test" and see if it only fires once. Then, send a really long message, and see how many times it fires. Divide the number of times it fired by the length of the message and you'll get a rough estimate of how many characters is max.

If the body text is the same, it should also be pretty simple to do a workaround by simply keeping the last message for a few minutes, and discard any identical messages.
 
Upvote 0

kohle

Active Member
Licensed User
Longtime User
The message is in the inbox only once, but the received event is triggered 2-3 times.
Yes, I can do a work arround to check the last received message with the new message and
write it only once in my database, no problem.
But, the phone lib should work like my stock android sms app (moto maxx).
One message, one trigger. But maybe the problem is the

'read SMS messages first to control application
SI.Initialize2("SI", 999)

Maybe should read the message not in the first place.
(Has no mean anymore, because under 4.4.4, sms can´t be killed anymore)

But this is only guessing.
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
In my case the messages were repeated all the time that the service was started ...easy 9 minutes on service start the message was there ...
as it nothing consumed the event !!!

the lib works just fine with long messages and trigers all ... you have to wait few seconds and put all the messages toghether to diplay all sms
 
Upvote 0
Top