Android Open Source - android_sdk S M S Receiver






From Project

Back to project page android_sdk.

License

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 (www.qubecell.com)
 *//*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";

  @Override
  public void onReceive(Context context, Intent intent) 
  {
    if(log == null)
    {
      log = new ELogger();
      log.setTag(TAG);
    }
    log.debug("SMSReceiver : Inside onReceive() method");
    Bundle bundle = intent.getExtras();
    log.info("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();
      }
      log.info("SMSReceiver : Receive message on port : "+ info);      
      
      if(BaseActivity.getReceiveSmsonPort() == 0)
      {
        BaseActivity.setReceiveSmsonPort(1);
        Intent resultIntent = new Intent(context, ResultActivity.class);
        resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        resultIntent.putExtra(IntentConstant.CLOSE_PROGRESSBAR, "true");
        if(msgBody.contains(String.valueOf(MsisdnServerRespCode.SUCCESS)))
        {      
          resultIntent.putExtra(IntentConstant.MESSAGE, "Thank you for your transaction.!");
          resultIntent.putExtra(IntentConstant.PAYMENT_RESULT, PaymentResult.SUCCESS);
        }
        else 
        {
          resultIntent.putExtra(IntentConstant.MESSAGE, MessageResponseCode.getResponseString(context, msgBody));
          resultIntent.putExtra(IntentConstant.PAYMENT_RESULT, PaymentResult.FALIURE);
        }
        context.startActivity(resultIntent);
      }
      else
      {
        log.info("Response timeout. Result will not displayed.");
      }
    }     
  }

  public int getMsgResponceCode(String msgBody)
  {
    return 101;
  }
}




Java Source Code List

com.qubecell.beans.BaseBean.java
com.qubecell.beans.CheckStatusRespBean.java
com.qubecell.beans.EventChargeRespBean.java
com.qubecell.beans.MsisdnRespBean.java
com.qubecell.beans.OperatorDetails.java
com.qubecell.beans.OperatorsRespBean.java
com.qubecell.beans.ResponseBaseBean.java
com.qubecell.beans.SendOTPRespBean.java
com.qubecell.beans.ValidateOTPRespBean.java
com.qubecell.constants.ApplicationActivities.java
com.qubecell.constants.CheckstatusServerRespCode.java
com.qubecell.constants.ConstantStrings.java
com.qubecell.constants.EventChargeServerRespCode.java
com.qubecell.constants.HttpConstant.java
com.qubecell.constants.IntentConstant.java
com.qubecell.constants.MerchantData.java
com.qubecell.constants.MessageResponseCode.java
com.qubecell.constants.MobileOperators.java
com.qubecell.constants.MsisdnServerRespCode.java
com.qubecell.constants.NetworkResponseCode.java
com.qubecell.constants.NetworkResponse.java
com.qubecell.constants.NetworkURL.java
com.qubecell.constants.PaymentResult.java
com.qubecell.constants.ProductIds.java
com.qubecell.constants.QubecellResult.java
com.qubecell.constants.SendOTPServerRespCode.java
com.qubecell.constants.ServerCommand.java
com.qubecell.constants.ThemeConfigurationVariables.java
com.qubecell.constants.ValidateOTPServerRespCode.java
com.qubecell.constants.WidgetsTagName.java
com.qubecell.elogger.ELogger.java
com.qubecell.network.AsyncClient.java
com.qubecell.network.NetworkController.java
com.qubecell.receivers.SMSReceiver.java
com.qubecell.smsmgr.QubecellSMSManager.java
com.qubecell.ui.BaseActivity.java
com.qubecell.ui.QubecellActivity.java
com.qubecell.ui.ResultActivity.java
com.qubecell.ui.SelectOperatorActivity.java
com.qubecell.ui.ValidateOTPActivity.java
com.qubecell.utility.CommonUtility.java
com.qubecell.utility.ImageBase64.java
com.qubecell.xmlparser.XMLParser.java
com.qubecell.xmlparser.XMLfunctions.java
com.qubecelltestapp.ui.MerchantActivity.java