安卓:从特定电话号码接收短信 [英] Android: Receiving SMS from specific phone number

查看:260
本文介绍了安卓:从特定电话号码接收短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为我的应用程序,以接收来自特定电话号码的短信,不让它trig的系统通知,但让所有的其他消息传递给默认的短信应用程序正常处理?

Is it possible for my application to receive an SMS from a specific phone number, without letting it trig a system notification, but let all other messages pass to the default SMS application to be treated normally?

如果是这样,怎么能系统了解其过程是先在队列中挑来接收的消息?

If so, how can the system know which process is first on queue to pick which messages to receive?

推荐答案

我没有尝试这一点,但在理论上它应该工作:

I didn't try this, but in theory it should work:

在Android的短信广播发送的有序广播,这意味着接收者为了进行处理,并可以取消播出。请参阅<一href="http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;f=telephony/java/com/android/internal/telephony/SMSDispatcher.java"相对=nofollow> SMSDispatcher.java ,线420。

In Android SMS broadcast is sent as ordered broadcast, which means that receivers are handled in order and can cancel the broadcast. See SMSDispatcher.java, line 420.

为了被先叫,接收器必须具有更高的优先级,然后其他人。

In order to be called first, a receiver must have a higher priority then others.

<intent-filter android:priority="1000" >
    . . .
</intent-filter>

要取消广播呼叫<一href="http://developer.android.com/reference/android/content/BroadcastReceiver.html#setResult$c$c%28int%29"相对=nofollow> broadcastReceiver.setResult code(RESULT_CANCELED) 。这样一个短信广播将被取消,不会被系统SMS应用程序(和短信通知)显示。

To cancel a broadcast call broadcastReceiver.setResultCode(RESULT_CANCELED). That way a SMS broadcast will be cancelled and will not be shown by system SMS app (and SMS notifier).

更新:

也可以尝试使用 broadcastReceiver.setResult code(Intents.RESULT_SMS_HANDLED)

更新2:

user672601指出,在另一个答案,这确实是工作,但他使用 abortBroadcast()广播接收器内。

user672601 noted in another answer that this indeed works, but he used abortBroadcast() inside broadcast receiver.

这篇关于安卓:从特定电话号码接收短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆