This is the class which support to send SMS.when we using SMS manager API we can't see any UI level change when sending message.
import android.content.Context; import android.telephony.SmsManager; import android.widget.Toast; public class SendSms { Context context; public SendSms(Context context){ this.context=context; } String phoneNo="telnumber(+9471 1111111)"; public void SendSms(String sms){ try { SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(phoneNo, null, sms, null, null); Toast.makeText(context, "SMS Sent!", Toast.LENGTH_LONG).show(); } catch (Exception e) { Toast.makeText(context, "SMS faild, please try again later!", Toast.LENGTH_LONG).show(); e.printStackTrace(); } } }
And make sure you have add SMS send uses-permission.
<uses-permission android:name="android.permission.SEND_SMS" />
And happy coding..
No comments:
Post a Comment