Getting Started with Android: texting and making calls

Source: Internet
Author: User


Package Com.example.sendsms;import Java.util.arraylist;import Android. R.array;import android.net.uri;import android.os.bundle;import Android.app.activity;import android.content.Intent; Import Android.telephony.smsmanager;import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;public Class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); final EditText txtnum = (EditText) This.findviewbyid ( R.id.txtnumber); final EditText txtbody = (EditText) This.findviewbyid (r.id.txtbody); Button btnsms = (button) This.findviewbyid (r.id.btnsend); Btnsms.setonclicklistener (new Onclicklistener () {@ overridepublic void OnClick (View arg0) {//TODO auto-generated method stubstring num = Txtnum.gettext (). toString (); String BODY = Txtbody.gettext (). toString (); Smsmanager manager = Smsmanager.getdefault (); Arraylist<string> list = Manager.dividemessage (body); for (String text:list) {manager.sendtextmessage (num, NULL, Body, NULL, NULL);}}); Button Btncall = (button) This.findviewbyid (R.id.btncall); Btncall.setonclicklistener (new Onclicklistener () {@  overridepublic void OnClick (View arg0) {//TODO auto-generated method stubstring num = Txtnum.gettext (). toString (); Intent Intent = new Intent (Intent.action_call,uri.parse ("Tel:" +num);//tel: It is necessary to do so startactivity (intent);});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu; This adds items to the action bar if it is PR Esent.getmenuinflater (). Inflate (R.menu.main, menu); return true;}}

(1)   Smsmanager manager = Smsmanager.getdefault (); Get the default message manager

(2)  arraylist<string> list = manager.dividemessage (String txt); Split Long text messages

(3) manager.sendtextmessage (String phone,null,string content,null,null); Send SMS


Add to Permissions




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Getting Started with Android: texting and making calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.