2011-11-10 34 views
2

是否有可能在后台使用smsInterceptor?我试图使用服务,但它不会工作,它不会在MessageReceived事件上为我发短信给我。smsInterceptor在后台?

'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 

这可能是错误的寿,我还没有想出如何做到这一点。阅读服务模块线程,但没有得到我的任何地方:/

回答

2

您将需要调用Service.StartForeground,以防止Android杀死你的服务。

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

+0

呵呵,谢谢。此外,我忘记将smsint_放在MessageReceived前dd 感谢您的快速响应。 – Adam