Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Auto-Reply to Texts Messages on Android device When Youre Busy

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 336
    Comment on it

    In certain cases, we are busy with some work and we don't have free time to reply our device incoming text messages. In that case, you will send an auto-reply message to all the incoming messages about your situation which goes something like this “I am currently driving and will call you back as soon as I am can” or any other. The user can either select a default message or customise a reply message depends on the need.

    Permission needed to add in your Android Manifest files

      <uses-permission android:name="android.permission.SEND_SMS"/>

    Creating a Broadcast Receiver class which receives an incoming SMS, on the basis of SMS we get the phone number of the sender.

    public class SmsListener extends BroadcastReceiver {
        private String phoneNumber;
    
        @Override
        public void onReceive(Context context, Intent intent) {
    
            // Retrieves a map of extended data from the intent.
            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]);
                        phoneNumber = currentMessage.getDisplayOriginatingAddress();
    
    		    // calling messageSend method
                        messageSend(phoneNumber, context); 
    
                    } // end for loop
                } // bundle is null
    
            } catch (Exception e) {
    
                Log.e("SmsReceiver", "Exception smsReceiver" +e);
            }
        }

     

    To send a reply message to the caller about user is busy and call you back

    public void messageSend(String incomingNumber, Context context) {
    
        String returnSms = "I am currently driving and will call you back as soon as possible";
    
             try {
                  	SmsManager smsManager = SmsManager.getDefault();
                  	smsManager.sendTextMessage(incomingNumber, null, returnSms, null, null);
                 
    	     } catch (Exception e) {
    
                  	e.printStackTrace();
                 }
        }
    }

     

    call this from the launcher or any other activity

    sendBroadcast(new Intent(HomeScreenActivity.this, SmsListener.class));

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: