Android Open Source - android_sdk S M S Receiver

From Project

Back to project page android_sdk.


The source code is released under:

GNU Lesser General Public License

If you think the Android project android_sdk listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

 * Copyright (C) 2013  Spunk Media Pvt Ltd (
 *//*from  ww  w .ja v a2 s  .  co m*/

package com.qubecell.receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;

import com.qubecell.constants.IntentConstant;
import com.qubecell.constants.MessageResponseCode;
import com.qubecell.constants.MsisdnServerRespCode;
import com.qubecell.constants.PaymentResult;
import com.qubecell.elogger.ELogger;
import com.qubecell.ui.BaseActivity;
import com.qubecell.ui.ResultActivity;

 * The SMSReceiver class is used to receive messages came to a specified port number.
 * @author Eninov
public class SMSReceiver extends BroadcastReceiver
  private ELogger log = null;
  private String TAG = "SMSReceiver";

  public void onReceive(Context context, Intent intent) 
    if(log == null)
      log = new ELogger();
    log.debug("SMSReceiver : Inside onReceive() method");
    Bundle bundle = intent.getExtras();"SMSReceiver : onreceive() : "+ bundle.toString());

    SmsMessage[] msgs = null;
    if(bundle != null)
      String info = "Text SMS from ";
      Object[] pdus = (Object[]) bundle.get("pdus");
      msgs = new SmsMessage[pdus.length];
      String msgBody = null;
      for (int i = 0; i < msgs.length; i++)
        msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);

        info += msgs[i].getOriginatingAddress();                    
        info += "\n*****TEXT MESSAGE*****\n";
        info += msgs[i].getMessageBody().toString();
        msgBody+= msgs[i].getMessageBody().toString();
      }"SMSReceiver : Receive message on port : "+ info);      
      if(BaseActivity.getReceiveSmsonPort() == 0)
        Intent resultIntent = new Intent(context, ResultActivity.class);
        resultIntent.putExtra(IntentConstant.CLOSE_PROGRESSBAR, "true");
          resultIntent.putExtra(IntentConstant.MESSAGE, "Thank you for your transaction.!");
          resultIntent.putExtra(IntentConstant.PAYMENT_RESULT, PaymentResult.SUCCESS);
          resultIntent.putExtra(IntentConstant.MESSAGE, MessageResponseCode.getResponseString(context, msgBody));
          resultIntent.putExtra(IntentConstant.PAYMENT_RESULT, PaymentResult.FALIURE);
      {"Response timeout. Result will not displayed.");

  public int getMsgResponceCode(String msgBody)
    return 101;

Java Source Code List