Android: SMS and phone number, android phone number

Source: Internet
Author: User

Android: SMS and phone number, android phone number


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.txt Number); final EditText txtBody = (EditText) encode Body); 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: Yes. startActivity (intent) ;}};}@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}

(1) SmsManager manager = SmsManager. getDefault (); // obtain the default message manager.

(2) ArrayList <String> list = manager. divideMessage (String txt); // split long messages

(3) manager. sendTextMessage (String phone, null, String content, null, null); // send SMS


Add to Permissions




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.