有没有办法拦截来袭短信,然后将其呈现给用户之前修改呢?
- 它可以用iPhone / Andriod的本身做了什么?
- 它可以使用PhoneGap的完成?
- 它可以使用MonoTouch的/单声道的的Andriod做些什么呢?
如果有任何上述情况,请您提供一些指引呢?
我的优选溶液优先顺序如下:
- PhoneGap的
- 单
- 本地人
谢谢大家!!
编辑:
人们想知道什么是这样做的目的,基本上我想提出一个词作为根据内容的短信一个“标签”,所以当我查看短信,我可以看到类似“重要提示:等等等等等等” ,而不是仅仅“等等等等等等”。
试试这个- //在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.
}
}
}
}
当然! iOS上最简单的方法就是创建SMS数据库的触发器 - /var/mobile/Library/SMS/sms.db
CREATE TRIGGER AFTER INSERT ON message
然后更新纪录!
这样做的更先进的方式,挂钩私有方法,但我不会去深,现在,你只需要探索的方法:)
顺便说一句,你在任何你需要一个越狱的设备
是的,有一种方法,但由于奇巧的部署遗憾的是它不那么容易了。 要在版本工作>果冻豆你必须有你的应用程序运行为默认的短信应用程序,这是修改和abortBroadcast()。 对于4.3及以下,创建一个广播接收器,做类似如下:
public void onReceive( Context context, Intent intent ) {
// Get the SMS map from Intent
Bundle extras = intent.getExtras();
String messages = "";
if ( extras != null ) {
// Get received SMS array
Object[] smsExtra = (Object[]) extras.get( SMS_EXTRA_NAME );
// Get ContentResolver object for pushing encrypted SMS to the incoming folder
ContentResolver contentResolver = context.getContentResolver();
for ( int i = 0; i < smsExtra.length; ++i ) {
SmsMessage sms = SmsMessage.createFromPdu((byte[])smsExtra[i]);
String body = sms.getMessageBody().toString();
String address = sms.getOriginatingAddress();
// Here is where you modify the body of the message!
messages += "SMS from " + address + " :\n";
messages += body + "\n";
putSmsToDatabase( contentResolver, sms );
}
}
}
private void putSmsToDatabase( ContentResolver contentResolver, SmsMessage sms ) {
// Create SMS row
ContentValues values = new ContentValues();
values.put( ADDRESS, sms.getOriginatingAddress() );
values.put( DATE, sms.getTimestampMillis() );
values.put( READ, MESSAGE_IS_NOT_READ );
values.put( STATUS, sms.getStatus() );
values.put( TYPE, MESSAGE_TYPE_INBOX );
values.put( SEEN, MESSAGE_IS_NOT_SEEN );
try {
values.put( BODY, sms.getMessageBody() ); // May need sms.getMessageBody.toString()
}
catch ( Exception e ) {
e.printStackTrace();
}
// Push row into the SMS table
contentResolver.insert( Uri.parse( SMS_URI ), values );
}
从获得此信息在这里
差点忘了... ..常数
public static final String SMS_EXTRA_NAME = "pdus";
public static final String SMS_URI = "content://sms";
public static final String ADDRESS = "address";
public static final String PERSON = "person";
public static final String DATE = "date";
public static final String READ = "read";
public static final String STATUS = "status";
public static final String TYPE = "type";
public static final String BODY = "body";
public static final String SEEN = "seen";
public static final int MESSAGE_TYPE_INBOX = 1;
public static final int MESSAGE_TYPE_SENT = 2;
public static final int MESSAGE_IS_NOT_READ = 0;
public static final int MESSAGE_IS_READ = 1;
public static final int MESSAGE_IS_NOT_SEEN = 0;
public static final int MESSAGE_IS_SEEN = 1;