Joke Collection Website - Public benefit messages - How to add the function of sending free SMS to Android system?

How to add the function of sending free SMS to Android system?

First, you should add the permission to send SMS to the program manifest file AndroidManifest.xml

& ltuses-permission Android:name = " Android . permission . send _ SMS "/& gt;

Includes two TextView components, two EditText components and a Button component, and adds a click event on the send button in the main program.

Private EditText txt _ num

Private EditText txt _ content

public void on create(Bundle saved instancestate){

super . oncreate(savedInstanceState);

setContentView(r . layout . main);

txt _ num =(EditText)this . findviewbyid(r . id . txt _ num);

txt _ content =(EditText)this . findviewbyid(r . id . txt _ content);

Button BTN _ send =(Button)this . findviewbyid(r . id . BTN _ send);

BTN _ send . setonclicklistener(new OnClickListener(){

Public void onClick (view v)

String str_num = txt_num.getText()。 toString(); //Get the phone number

string str _ content = txt _ content . gettext()。 toString(); //Get the short message content

SMS manager manager _ SMS = SMS manager . get default(); //Get the SMS Manager.

//Because the message may be longer, split the message.

ArrayList & lt string & gt texts = SMS manager. Divide message (str _ content);

For (string text: text) (

SMS manager . sendtextmessage(str _ num,null,text,null,null); //Send each message separately.

}

Toast. Maketext (SMS activity. This, "sent successfully!" , toast. Length _ length). show(); //Prompt success

}

});

}

At this point, the function of sending SMS has been introduced.