smsInterceptor在后台?

时间:2011-11-10 17:06:47

标签: basic4android

是否可以在后台使用smsInterceptor?我正在尝试使用服务,但它不起作用,它不会在MessageReceived事件上为我提供短信消息。

'Service module
Sub Process_Globals 
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim smsint As SmsInterceptor
End Sub

Sub Service_Create
smsint.Initialize("smsint")
End Sub

Sub Service_Start (StartingIntent As Intent)
    StartServiceAt("", DateTime.Now + 30 * DateTime.TicksPerSecond, True)
End Sub

Sub Service_Destroy

End Sub

Sub MessageReceived (From As String, Body As String)
    ToastMessageShow(From & " - " & Body, True)
End Sub

这可能是错的,我还没弄明白怎么做。阅读服务模块线程,但没有把我带到任何地方:/

1 个答案:

答案 0 :(得分:2)

您需要致电Service.StartForeground以防止Android终止您的服务。

另一种选择是修改清单文件并为SMS添加意图过滤器。在这种情况下,Android会在短信到达时自动启动您的服务。