use of android.telephony.gsm.SmsMessage in project android-demos by novoda.
the class SmsReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
//---get the SMS message passed in---
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].getMessageBody().toString();
str += "\n";
}
//---display the new SMS message---
Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
}
}
use of android.telephony.gsm.SmsMessage in project 360-Engine-for-Android by 360.
the class SmsBroadcastReceiver method onReceive.
/**
* Implementation of the {@link BroadcastReceiver#onReceive} function.
* Decodes Hessian from SMS text and broadcasts the data to the engines
*
* @param context The current context of the People application
* @param intent Intent containing the SMS data
*/
@Override
public void onReceive(Context context, Intent intent) {
LogUtils.logD("SmsBroadcastReceiver.onReceive - Begin of sms receiver. \n" + intent.toString());
Bundle bundle = intent.getExtras();
Object[] messages = (Object[]) bundle.get("pdus");
SmsMessage[] smsMessage = new SmsMessage[messages.length];
for (int n = 0; n < messages.length; n++) {
try {
smsMessage[n] = SmsMessage.createFromPdu((byte[]) messages[n]);
LogUtils.logD("SmsBroadcastReceiver.onReceive - SMS no [" + n + "]bytes: " + new String(smsMessage[n].getUserData()));
HessianDecoder hd = new HessianDecoder();
Hashtable<String, Object> ht = hd.decodeHessianByteArrayToHashtable(smsMessage[n].getUserData());
if (ht != null) {
LogUtils.logD("SmsBroadcastReceiver.onReceive - Decoded hashtable: " + ht.toString());
Hashtable<?, ?> codeTable = (Hashtable<?, ?>) ht.get("e");
String code = (String) codeTable.get("r");
LogUtils.logD("SmsBroadcastReceiver.onReceive - Activation code: " + code);
Intent in = new Intent(ACTION_ACTIVATION_CODE);
in.putExtra("code", code);
context.sendBroadcast(in);
} else {
String code = "No code in SMS";
LogUtils.logD("SmsBroadcastReceiver.onReceive - Code not in sms");
Intent in = new Intent(ACTION_ACTIVATION_CODE);
in.putExtra("code", code);
context.sendBroadcast(in);
}
} catch (IOException e) {
LogUtils.logE("SmsBroadcastReceiver.onReceive() " + "IOException while decoding SMS Message.", e);
}
}
}
Aggregations