简体   繁体   中英

How to send a delayed auto reply to received SMS

What I want to do is have the app triggered by any incoming text message while the app is active. Upon receiving the SMS, I want it to have a delay (set by the user) in seconds before it sends an auto-reply automatically without the user's intervention.

What I have so far is:

public void onReceive(Context context, Intent intent) {
     //---get the SMS message passed in---        
    Bundle bundle = intent.getExtras();                  
    if (bundle != null)        {           
        //assuming the message exists... what to do now?      
        }
}

I haven't been able to find any documentation on this, so if there is any available that anyone knows of, please link. Or if there is a good example, please answer with as well.

To clarify, I'm looking for 2 things -- 1) How to do the delay 2) How to do the auto-reply

final Runnable r = new Runnable()
{
    public void run() 
    {
        //Send code for automatice message response

    }
};

handler.postDelayed(r, 1000);

Take object of handler as global and use it above way

you could use Android AlaramManager to do the task.(which won't work at times)

or else you can run a timer loop to do the delay(which is less preferable coz it holds lots of memory).

or you can use an Asynchronous thread to run the task with a delay.

The choice is yours.

new Handler().postDelayed(new Runnable() {

@Override
public void run() {

    // code for reply of SMS

}

    }, DelayOfReplySMSTime);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM