List of usage examples for android.telephony SmsMessage getDisplayMessageBody
public String getDisplayMessageBody()
From source file:com.demo.android.smsapp.receivers.SMSReceiver.java
@Override public void onReceive(Context context, Intent intent) { final Bundle bundle = intent.getExtras(); try {//from ww w . j a v a2 s . c om if (bundle != null) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); String message = currentMessage.getDisplayMessageBody(); Intent chatActivityIntent = new Intent(context, SMSChatActivity.class); chatActivityIntent.putExtra("number", phoneNumber); PendingIntent pi = PendingIntent.getActivity(context, 1, chatActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.mipmap.ic_launcher).setContentTitle(phoneNumber).setContentText(message) .setContentIntent(pi) .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); notificationManager.notify(99, mBuilder.build()); Log.i("SmsReceiver", "senderNum: " + phoneNumber + "; message: " + message); } } } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } }
From source file:com.oodles.smslistener.SmsListenerModule.java
void setupIntentReceivers() { Log.d(LCAT, "inside setupIntentReceivers"); Activity currentActivity = TiApplication.getInstance().getCurrentActivity(); //let's register broadcast receivers BroadcastReceiver smsReceiver = new BroadcastReceiver() { @Override/* w w w. j av a 2 s .c om*/ public void onReceive(Context context, Intent intent) { Log.d(LCAT, "inside onReceive"); KrollDict event; switch (getResultCode()) { case Activity.RESULT_OK: final Bundle bundle = intent.getExtras(); try { if (bundle != null) { final Object[] pdusObj = (Object[]) bundle.get("pdus"); for (int i = 0; i < pdusObj.length; i++) { SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]); String phoneNumber = currentMessage.getDisplayOriginatingAddress(); senderNum = phoneNumber; message = currentMessage.getDisplayMessageBody(); } } } catch (Exception e) { Log.e("SmsReceiver", "Exception smsReceiver" + e); } event = createEventObject(true, RECEIVED, message, senderNum); Log.d(LCAT, "message Received"); fireEvent("complete", event); break; default: event = createEventObject(false, FAILED, "Message delivery failed", ""); Log.d(LCAT, "message receiving failure"); fireEvent("complete", event); break; } } }; IntentFilter intentFilter = new IntentFilter(); intentFilter.setPriority(1000); intentFilter.addAction(MESSAGE_RECEIVED); //---when the SMS has been Received--- currentActivity.registerReceiver(smsReceiver, intentFilter); }
From source file:com.polyvi.xface.extension.messaging.XMessagingExt.java
/** * ?json/*w w w . j a va 2 s . c om*/ * */ private JSONObject buildSmsJsonObj(SmsMessage msg) throws JSONException { JSONObject msgJsonObj = new JSONObject(); msgJsonObj.put("msgId", ""); msgJsonObj.put("subject", msg.getPseudoSubject()); msgJsonObj.put("body", msg.getDisplayMessageBody()); msgJsonObj.put("destinationAddresses", ""); msgJsonObj.put("originatingAddress", msg.getDisplayOriginatingAddress()); msgJsonObj.put("messageType", "SMS"); boolean isRead = false; if (SmsManager.STATUS_ON_ICC_READ == msg.getStatusOnIcc()) { isRead = true; } msgJsonObj.put("isRead", isRead); msgJsonObj.put("date", msg.getTimestampMillis()); return msgJsonObj; }