Android Question toast when SMS received ?

Devv

Active Member
Licensed User
Longtime User
I'm trying to make a service that toast i got a message each time i receive an sms even if the app was not running

this is what i tried

B4X:
Sub Process_Globals

Type Message (Address As String, Body As String)
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")

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub Service_Start(startingIntent As Intent)
  If startingIntent.Action = "android.provider.Telephony.SMS_RECEIVED" Then
  ToastMessageShow("gow a new message",True)
  End If
end  sub



the mainfest file

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
AddPermission(android.permission.RECEIVE_SMS)
AddReceiverText(s1,
<intent-filter>
    <action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>)
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.



any ideas ?
 

Devv

Active Member
Licensed User
Longtime User
@Erel
my code must be in a service module not in a activity module right ?
i'm getting this when i press F5

B4X:
Parsing code.                          0.06
Compiling code.                        Error
Module: s1_br not found.
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
hi erel
im new to basic may you please take a look at the project , it is attached
 

Attachments

  • new.zip
    6.6 KB · Views: 167
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
B4X:
AddReceiverText(s1,
this is you error, your service is named "test", so chenge into manifest to:

B4X:
AddReceiverText(test,
 
Upvote 0

Devv

Active Member
Licensed User
Longtime User
B4X:
AddReceiverText(s1,
this is you error, your service is named "test", so chenge into manifest to:

B4X:
AddReceiverText(test,


thanks bro it worked!

how can i pass the sms to the android sms app or not ?
their is no sub so i can return true or false
 
Upvote 0
Top