拦截来袭的短信消息并对其进行修改 [英] Intercept Incoming SMS Message and Modify it

查看:233
本文介绍了拦截来袭的短信消息并对其进行修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法拦截传入的短信,然后$ P $之前修改它psenting用户?

Is there a way to intercept an incoming SMS message, and then modify it before presenting it to the user?

  • 可不可以这样本身在iPhone / Andriod的呢?
  • 可以使用它的PhoneGap做?
  • 是否可以使用MonoTouch的/单声道的的Andr​​iod做些什么呢?

如果是肯定的上述情况,请您提供一些指引呢?

If yes to any of the above, could you please provide some pointers to it?

我的preferred-解决方案优先顺序如下:

My preferred-solution priority-order is as follows:

  1. 的PhoneGap
  2. 在单
  3. 本机

感谢大家提前!!

编辑:

有关的人不知道什么是这样做的目的,基本上我想提出一个字作为一个依赖于内容的短信标签,所以当我查看短信,我能看到类似重要提示:胡说等等等等,而不仅仅是等等等等。

For people wondering what is the purpose of this, basically I would like to put a word as a "label" in the sms depending on the content, so when I view the sms, I can see something like "IMPORTANT: blah blah blah", instead of just "blah blah blah".

推荐答案

试试这个 - //注册这个类接收器清单文件的SMS_RECEIVED意图

  public class SmsReceiver extends BroadcastReceiver {

    private static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";

    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(SMS_RECEIVED)) {
              abortBroadcast();**this is prevent message to deliver to user**

            Bundle bundle = intent.getExtras();
            if (bundle != null) {
                // get sms objects
                Object[] pdus = (Object[]) bundle.get("pdus");
                if (pdus.length == 0) {
                    return;
                }
                // large message might be broken into many
                SmsMessage[] messages = new SmsMessage[pdus.length];
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < pdus.length; i++) {
                    messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
                    sb.append(messages[i].getMessageBody());
                }
                String sender = messages[0].getOriginatingAddress();
                String message = sb.toString();
                Toast.makeText(context, message, Toast.LENGTH_SHORT).show();

               SmsManager sms = SmsManager.getDefault();
               sms.sendTextMessage(phoneNumber, null, message, null, null);//phone number will be your number. 
            }
        }
    }
}

这篇关于拦截来袭的短信消息并对其进行修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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