Is it possible to intercept an SMS coming from a certain number and direct it to a certain application on the iPhone开发者_如何转开发/Android where it will be processed? Thanks.
In Android, what you can do is register a BroadcastReceiver
to be notified that an SMS has been received, mark the message as read in the SMS Content Provider and then delete that specific message from the content provider. This will prevent any other applications from being able to read the message once you have deleted it and no notifications will be shown in the notification space. That said, I have no idea what will happen to the applications that receive the Intent indicating that a message has been received but then cannot access it in the database. This could result in unpredictable behavior as a result of a number of race conditions.
Yes. It is possible in Android. I'm doing it in an app I'm developing. What you need to do is:
public class SMSService extends BroadcastReceiver {
public static final String SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private String phoneNumber;
private String sms;
private Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
if (intent.getAction().equals(SMS_RECEIVED)) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
for (int i = 0; i < msgs.length; i++) {
msgs[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
// get sms message
sms = msgs[i].getMessageBody();
// get phone number
phoneNumber = msgs[i].getOriginatingAddress();
if (phoneNumber.equals("Some other phone number")){
// the sms will not reach normal sms app
abortBroadcast();
Thread thread = new Thread(null,
doBackgroundThreadProcessing, "Background");
thread.start();
}
}
}
}
}
private Runnable doBackgroundThreadProcessing = new Runnable() {
// do whatever you want
};
IMPORTANT: In manifest file you have to define SMS priority with an high number. I believe the max is 100.
<!-- SMS Service -->
<service android:name=".SMSService" />
<receiver android:name=".SMSService">
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
For Android the answer is no. You can implement a BroadcastReceiver
that is called whenever the device receives an SMS text message but cannot keep other applications (e.g. the built-in Messaging app) from receiving them too.
For Android the answer is Yes.
android.provider.Telephony.SMS_RECEIVED
event is an ordered broadcast and you can tune the priority. This means your application will receive the event before everyone else. And you can cancel Broadcast for the rest of Broadcast Receivers.
You can find more information here: stackoverflow.com/can-we-delete-an-sms-in-android-before-it-reaches-the-inbox/
In Android, once you received an SMS message in your application, you can use an Intent object to pass the details of the message to another activity/application for further processing. If you need to pass the message to your own application, use the sendBroadcast() method to broadcast the Intent object. In your activity, you would just need to use the registerReceiver() method to listen for the broadcast.
Hope it helps! Wei-Meng Lee
精彩评论