本文介绍了截取收到的短信并修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法拦截传入的 SMS 消息,然后在将其呈现给用户之前对其进行修改?
Is there a way to intercept an incoming SMS message, and then modify it before presenting it to the user?
- 能否在 iPhone/Andriod 上本地完成?
- 可以使用 PhoneGap 来完成吗?
- 是否可以使用 MonoTouch/Mono for Andriod 来完成?
如果以上任何一条是肯定的,请您提供一些指示吗?
If yes to any of the above, could you please provide some pointers to it?
我的首选解决方案优先顺序如下:
My preferred-solution priority-order is as follows:
- Phonegap
- 单声道
- 本地
先谢谢大家!!
对于想知道这是什么目的的人,基本上我想根据内容在短信中添加一个词作为标签",所以当我查看短信时,我可以看到类似重要:等等等等",而不仅仅是等等等等".
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.
}
}
}
}
这篇关于截取收到的短信并修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!