How to send free SMS in android..i want to know WhatsApp,Wechat ..this type of messeging applications how provide us sending messege for free -


this code sending sms

import android.app.activity; import android.app.pendingintent; import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.content.intentfilter; import android.os.bundle; import android.telephony.smsmanager; import android.view.view; import android.widget.button; import android.widget.edittext; import android.widget.toast; public class smstest extends activity { button btnsendsms; edittext txtphoneno; edittext txtmessage;  

called when activity first created.

@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.sendingsms); btnsendsms = (button) findviewbyid(r.id.btnsendsms); txtphoneno = (edittext) findviewbyid(r.id.txtphoneno); txtmessage = (edittext) findviewbyid(r.id.txtmessage);   btnsendsms.setonclicklistener(new view.onclicklistener() { public void onclick(view v) { string phoneno = txtphoneno.gettext().tostring(); string message = txtmessage.gettext().tostring(); if (phoneno.length()>0 && message.length()>0) sendsms(phoneno, message); else toast.maketext(getbasecontext(), "please enter both phone number , message.", toast.length_short).show(); } }); } 

sends sms message device

private void sendsms(string phonenumber, string message) {  string sent = "sms_sent"; string delivered = "sms_delivered";  pendingintent sentpi = pendingintent.getbroadcast(this, 0, new intent(sent), 0);  pendingintent deliveredpi = pendingintent.getbroadcast(this, 0, new intent(delivered), 0);  //—when sms has been sent— registerreceiver(new broadcastreceiver(){ @override public void onreceive(context arg0, intent arg1) { switch (getresultcode()) { case activity.result_ok: toast.maketext(getbasecontext(), "sms sent", toast.length_short).show(); break; case smsmanager.result_error_generic_failure: toast.maketext(getbasecontext(), "generic failure", toast.length_short).show(); break; case smsmanager.result_error_no_service: toast.maketext(getbasecontext(), "no service", toast.length_short).show(); break; case smsmanager.result_error_null_pdu: toast.maketext(getbasecontext(), "null pdu", toast.length_short).show(); break; case smsmanager.result_error_radio_off: toast.maketext(getbasecontext(), "radio off", toast.length_short).show(); break; } } }, new intentfilter(sent));  //—when sms has been delivered— registerreceiver(new broadcastreceiver(){ @override public void onreceive(context arg0, intent arg1) { switch (getresultcode()) { case activity.result_ok: toast.maketext(getbasecontext(), "sms delivered", toast.length_short).show(); break; case activity.result_canceled: toast.maketext(getbasecontext(), "sms not delivered", toast.length_short).show(); break; } } }, new intentfilter(delivered));  smsmanager sms = smsmanager.getdefault(); sms.sendtextmessage(phonenumber, null, message, sentpi, deliveredpi); } } 

this code receive sms

import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.os.bundle; import android.telephony.smsmessage; import android.widget.toast;  public class smsreceiver extends broadcastreceiver { @override public void onreceive(context context, intent intent) { //—get sms message passed in— bundle bundle = intent.getextras(); smsmessage[] msgs = null; string str = ""; if (bundle != null) { //—retrieve sms message received— object[] pdus = (object[]) bundle.get("pdus"); msgs = new smsmessage[pdus.length]; (int i=0; i<msgs.length; i++){ msgs[i] = smsmessage.createfrompdu((byte[])pdus[i]); str += "sms " + msgs[i].getoriginatingaddress(); str += " :"; str += msgs[i].getmessagebody().tostring(); str += "\n"; } //—display new sms message— toast.maketext(context, str, toast.length_short).show(); } } } 

and xml file..

<?xml version="1.0" encoding="utf-8"?>     <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     >     <textview     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="enter phone number of recipient"     />     <edittext     android:id="@+id/txtphoneno"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     />     <textview     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="message"     />     <edittext     android:id="@+id/txtmessage"     android:layout_width="fill_parent"     android:layout_height="150px"     android:gravity="top"     />     <button     android:id="@+id/btnsendsms"     android:layout_width="fill_parent"     android:layout_height="wrap_content"     android:text="send sms"     />     </linearlayout> 

very basic application ..i need know possible send sms through coding ...if not how whatsapp gives permission send sms free..does pay??..or can use api...

whatsapp doesnt use operator-based sms in application, whatsapp has own servers, when open app, you're connected server, when friend login, both of connected server, @ moment there open channel between both of you, use chat , send files , etc

simple, isn't :)


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -