用于发送短信的 Android 广播接收器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/990558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android Broadcast Receiver for Sent SMS messages?
提问by Josef Pfleger
I created a BroadcastReceiver
and configured it with an android.provider.Telephony.SMS_RECEIVED
action filter so it is called everytime the phone receivesa text.
我创建了一个BroadcastReceiver
并配置了一个android.provider.Telephony.SMS_RECEIVED
动作过滤器,因此每次手机收到文本时都会调用它。
Is there some event/action or other way for my application to be notified whenever the phone sendsa text (preferably independent of the application that sends it)?
每当手机发送文本(最好独立于发送文本的应用程序)时,是否有某种事件/操作或其他方式可以通知我的应用程序?
So far the only option I see is to poll the content provider for content://sms/sent
which doesn't even give me all sent texts because applications can choose not to put it there.
到目前为止,我看到的唯一选择是轮询内容提供者,content://sms/sent
因为应用程序可以选择不把它放在那里,因为它甚至不给我所有发送的文本。
采纳答案by Josef Pfleger
Unfortunately there is (currently) no way to implement a BroadcastReceiver
because the standard sms application uses a SmsManger
to send the messages but specifies concrete internal classes for the sent and delivered intents (SmsReceiver.class
and MessageStatusReceiver.class
respectively). Not that it is any consolation but you can find the following comment in the Sms application's source:
不幸的是,(目前)没有办法实现BroadcastReceiver
,因为手机短信的标准应用程序使用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.
The best alternative seems to be polling content://sms/sent
, potentially using a ContentObserver
.
最好的选择似乎是轮询content://sms/sent
,可能使用ContentObserver
.