用于发送短信的Android广播接收器?

Jos*_*ger 24 sms android broadcastreceiver

我创建了一个BroadcastReceiver并使用android.provider.Telephony.SMS_RECEIVED动作过滤器对其进行配置,以便每次手机接收到文本时都会调用它.

是否有一些事件/操作或其他方式可以在手机发送文本时通知我的应用程序(最好是独立于发送它的应用程序)?

到目前为止,我看到的唯一选择是轮询内容提供商content://sms/sent甚至没有给我所有发送的文本,因为应用程序可以选择不将它放在那里.

Jos*_*ger 21

遗憾的是(目前)没有办法实现a,BroadcastReceiver因为标准的sms应用程序使用a SmsManger来发送消息,但是为发送和传递的意图(SmsReceiver.class以及MessageStatusReceiver.class分别)指定了具体的内部类.并不是说它有任何安慰,但您可以在Sms应用程序的源代码中找到以下注释:

// TODO: Fix: It should not be necessary to
// specify the class in this intent.  Doing that
// unnecessarily limits customizability.
Run Code Online (Sandbox Code Playgroud)

最好的选择似乎是轮询content://sms/sent,可能使用a ContentObserver.