Search code examples
androidsmsmanager

Unable to send sms programatically in android


Hi i am a new android developer.i am trying to send sms through android built-in service SmsManager class my code is running accurately but the message sent through this is not received to other number.My code is as follows

      btnSend.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            String ph=et1.getText().toString();
            String text=et2.getText().toString();
            try{
            SmsManager sms=SmsManager.getDefault();
            sms.sendTextMessage(ph,null, text,null,null);
            Toast.makeText(getApplicationContext(), "sent", Toast.LENGTH_SHORT).show();
            }
            catch(Exception e)
            {
                Toast.makeText(getApplicationContext(), "Message not sent", Toast.LENGTH_SHORT).show();
            }

        }
    });

Solution

    • Please check following permission

      android.permission.SEND_SMS