Dhruvin shah February 2016

How can I check whether response is came within one minute after sending SMS in android?

I am creating an application in which I am sending SMS automatically on button click.When SMS is sent I get a response from server in form of SMS.I read that message and perform task on it. Now problem is that when I receive SMS I want to consider only messages received within one minute after button click. What to do.?

public class IncomingSms extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent)
{



    Global mApplication = ((Global)context.getApplicationContext());
    String getPPN=mApplication.getPPN();
    String getStatus=mApplication.getvStatus();
    String ClientId=mApplication.getvClientId();
    String MobileNo=mApplication.getvStrMobile();
    String LocationId=mApplication.getVstrLocation();
    String IMEI=mApplication.getVstrIMEI();

    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();
                String senderNum = phoneNumber ;



                String message = currentMessage .getDisplayMessageBody();

                mApplication.setvSenderNumber(senderNum);
                mApplication.setvMessageBody(message);
                String IsBroadCast=mApplication.getvAuthenticatedUser();

                try
                {
                    if(IsBroadCast=="1")
                    {
                        context.sendBroadcast(new Intent("Message_Recived"));
                    }




                }
                catch(Exception e){}

            }
        }

    } catch (Exception e)
    {

    }
}

}

This class is called when SMS received and take me to Arming Activity's on receive method. But I need

Answers


SID February 2016

you can do this with the Handler

for that start/register receiver and also start the Handler for the one minute

//start your broadcast here.
new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // write code to stop/unregister receiver.

        }
    }, 60*1000);

for further display time you can use CountDownTimer class.

Post Status

Asked in February 2016
Viewed 3,139 times
Voted 14
Answered 1 times

Search




Leave an answer