Please can I get advice?
I am trying receive SMS and I want this SMS write to Label
I am using this code - I find code on forum
http://www.b4x.com/android/forum/threads/receiving-sms.31210/#content
Because in example was not CallSubDelayed2, I add CallSubDelayed2 in service module
I add to manifesteditor:
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(serviceforsms,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
serviceforsms is name of my service module, is this correct please?
I have trouble, that when I receive SMS the program is shut down and I must reopen the program. Please, what I am doing wrong?
Thank you very much
p4ppc
Manifest EDITOR:
Service: name of serice=serviceforsms
SUB IN MAIN MODULE for catching SMS:
I am trying receive SMS and I want this SMS write to Label
I am using this code - I find code on forum
http://www.b4x.com/android/forum/threads/receiving-sms.31210/#content
Because in example was not CallSubDelayed2, I add CallSubDelayed2 in service module
I add to manifesteditor:
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(serviceforsms,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
serviceforsms is name of my service module, is this correct please?
I have trouble, that when I receive SMS the program is shut down and I must reopen the program. Please, what I am doing wrong?
Thank you very much
p4ppc
Manifest EDITOR:
B4X:
'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"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
AddPermission(android.permission.MODIFY_AUDIO_SETTINGS)
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(serviceforsms,
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
'End of default text.
Service: name of serice=serviceforsms
B4X:
Sub Service_Destroy
End Sub
'Service module
Sub Process_Globals
Type Message (Address As String, Body As String)
End Sub
Sub Service_Create
End Sub
Sub Service_Start(startingIntent As Intent)
If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
Dim messages() As Message
messages = ParseSmsIntent(startingIntent)
For i = 0 To messages.Length - 1
Log(messages(i))
Next
End If
End Sub
'Parses an SMS intent and returns an array of messages
Sub ParseSmsIntent (In As Intent) As Message()
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
Dim messages(pdus.Length) As Message
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")
Next
CallSubDelayed2(Main, "subsms", messages(i).Address & "-" & messages(i).Body)
End If
Return messages
End Sub
SUB IN MAIN MODULE for catching SMS:
B4X:
Sub subsms(Result AsString)
Label1.Text=Result
End sub