2

是否可以在后台使用 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

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

4

1 回答 1

2

您需要调用 Service.StartForeground 以防止 Android 终止您的服务。

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

于 2011-11-10T17:48:04.767 回答