I want to monitor Event "OUTGOING SMS" Programmatically?
I have got Event "Incoming SMS" just like this code.
public class IncomingSmsCaptureApp extends BroadcastReceiver {
private static final String ACTION_NEW_OUTGOING_SMS = "android.provider.Telephony.NEW_OUTGOING_SMS";
private static final String ACTION_SMS_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
private String action;
@Override
public void onReceive(Context context, Intent intent) {
// ---get the SMS message passed in---
action = intent.getAction();
if (ACTION_SMS_RECEIVED.equals(action)) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str = "";
if (bundle != null) {
// ---retrieve the SMS message received---
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]);
str += "SMS from " + msgs[i].getOriginatingAddress();
str += " :";
str += msgs[i].getM开发者_开发技巧essageBody().toString();
str += "\n";
}
// ---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
} else {
onSending(context, intent);
}
}
public void onSending(Context context, Intent intent) {
action = intent.getAction();
if (action.equals(ACTION_NEW_OUTGOING_SMS)) {
Toast.makeText(context, "Test Capture SMS Sending Success",
Toast.LENGTH_SHORT).show();
}
}
}
I use this code for monitor Event "OUTGOING SMS". It is not work.
My application want to get "Action" when have "OUTGOING SMS". Is it possible? I didn't find answer for this problem.
Help me please. Sorry for my bad English.
精彩评论