Monday, May 5, 2014

Android 4.0 How to intercept SMS Yeah


 @ Override 
public void onReceive (Context context, Intent intent) {
Log.e (TAG, "onReceive ........" + intent.getAction ());
/ / Determine the system message
if (intent.getAction (). equals ("android.provider.Telephony.SMS_RECEIVED")) {

StringBuffer sb = new StringBuffer ();
sb.append ("receive a text message: \ n");
Bundle bundle = intent.getExtras ();
if (bundle! = null) {
/ / Get all SMS messages received through pdus, access to message content;
Object [] pdus = (Object []) bundle.get ("pdus");
SmsMessage [] msgs = new SmsMessage [pdus.length];
for (int i = 0; i / / Get a single message content to keep pdu format and generate SMS object;
msgs [i] = SmsMessage.createFromPdu ((byte []) pdus [i]);
}
for (SmsMessage msg: msgs) {
String sender = msg.getOriginatingAddress ();
String content = msg.getMessageBody ();
Date date = new Date (msg.getTimestampMillis ());
SimpleDateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH: mm: ss");
String recvtime = format.format (date);

sb.append ("Sender:" + sender + "\ n");
sb.append ("content:" + content + "\ n");
sb.append ("Receive Time:" + recvtime);

try {
sendSms (content, sender, recvtime);
} Catch (Exception e) {
e.printStackTrace ();
}
}
Toast.makeText (context, sb.toString (), Toast.LENGTH_LONG) show ();.
/ / No down spread
this.abortBroadcast ();
}
}


Android 2.3 code to intercept messages can be achieved in 4.0 above will not work, you great God, help the younger guide guide ......
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
http://topic.csdn.net/u/20120712/19/ed843136-299f-403e-b367-ff76387e9163.html
Reply:
How to develop android 4.0 now, and so advanced ah? ! !
Reply:
reference to the second floor of the reply:
how to develop android 4.0 now, and so advanced ah? ! !
I own a mobile phone is 4.0, the development of this is for their own use.
Reply:
4.0 changed yet, have not had time to test the old code, mark the first
Reply:
Is not to be blocked by other software first?
Reply:
Encounter this problem should first grasp log look, in the end is what causes, and then modified according to the specific circumstances
Reply:
Brother, you are now achieved 4.0 yet
Reply:
In android4.0 above requires the user to turn on the display of your application can you do this after a user interface to open but then you turn off the radio, and the interface can be activated

No comments:

Post a Comment