This article describes the development of Android Phone Dialer and SMS transmitter implementation methods. Share to everyone for your reference, specific as follows:
Phone Dialer
Realization principle: The user enters the telephone number, when clicks dials, by listens for the object capture, listens for the object through the text control obtains to the user to enter the telephone number, because the system has realized the telephone dialing function, therefore we only need to call this function to be possible.
Steps:
1. Interface layout
2. Preparation of activity
3. Use Intent filter to activate phone dialing function
4. Add telephony privileges (use mobile phone service to add telephony privileges to the manifest file Androidmanifest.xml)
As the figure shows, these three controls are placed vertically, so use a linear layout to shelve the display controls
Effect Chart:
Interface layout:
<?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"
>
<!--prompting information-->
<textview
android:layout_width= "Fill_parent"
android:layout_height= "wrap_content"
android:text= "@string/mobile"
/>
<!--text Box button-- >
<edittext
android:layout_width= "fill_parent"
android:layout_height= "Wrap_content"
Android:id= "@+id/moblie"
/>
<!--dialing button-->
<button android:layout_width=
"Wrap_ Content "
android:layout_height=" wrap_content "
android:text=" @string/button "
android:id=" @+id/ Button "
/>
</LinearLayout>
Activity:
Package cn.test.phone;
Import android.app.Activity;
Import android.content.Intent;
Import Android.net.Uri;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.Button;
Import Android.widget.EditText; public class Mainactivity extends activity {@Override public void onCreate (Bundle savedinstancestate) {super.
OnCreate (savedinstancestate);
Setcontentview (R.layout.main);
Finds the button control buttons button = (Button) This.findviewbyid (R.id.button) based on the ID of the control; Button.setonclicklistener (New Buttonclicklister ()); Click on the processing object of the event}//Listener Object Realization dial function Private class Buttonclicklister implements view.onclicklistener{public void Oncl
Ick (View v) {edittext mobiletext= (edittext) Findviewbyid (R.id.moblie); String Moblie=mobiletext.gettext (). toString ();
Gets the time entered by the user Intent Intent =new Intent ();
Intent.setaction ("Android.intent.action.CALL");
Intent.setdata (Uri.parse ("Tel:" +moblie)); Activate the phone dialing function according to the intent filter parameter StArtactivity (Intent);
}
}
}
To add a Telephony service permission:
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" cn.itcast.action "
android:versioncode=" 1 "
android:versionname=" 1.0 ">
....
<USES-SDK android:minsdkversion= "6"/>
<!--telephony permissions-->
<uses-permission android:name= " Android.permission.CALL_PHONE "/>
</manifest>
SMS Transmitter
SMS Transmitter and Phone Dialer step similar to the need to note that when the content of the text message, if the message content is very much need to split the text message, split, and then save to the collection, the text of a number of message sent
Effect Chart:
Interface layout:
<?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 "
> <!--Display control--> <textview android:layout_width= "fill_parent" android:layout_height= "Wrap_content"
android:text= "@string/moblie"/> <!--text Box button--> <edittext android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:id= "@+id/moblie" "/> <textview android:layout_width=" fill _parent "android:layout_height=" wrap_content "android:text=" @string/content "/> <edittext android:l
Ayout_width= "Fill_parent" android:layout_height= "Wrap_content" android:minlines= "3" android:id= "@+id/content" /> <button android:layout_width= "wrap_content android:layout_height=" wrap_content "android:text=" @str Ing/button "Android:id=" @+id/Button "/> </LinearLayout>
activity:
Package cn.test.sms;
Import java.util.ArrayList;
Import android.app.Activity;
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 Mainactivity extends activity {@Override public void onCreate (Bundle savedinstancestate) {super.
OnCreate (savedinstancestate);
Setcontentview (R.layout.main);
Button button = (button) This.findviewbyid (R.id.button); Button.setonclicklistener (New Buttonclicklister ()); Click on the processing object of the event}//Listener Object Realization dial function Private class Buttonclicklister implements view.onclicklistener{public void Oncl
Ick (View v) {edittext moblietext= (edittext) Findviewbyid (R.id.moblie);
EditText contenttext= (EditText) Findviewbyid (r.id.content);
String Moble =moblietext.gettext (). ToString ();//Get phone number string content =contenttext.gettext (). ToString ();//Get text message Smsmanager Smsmanager=smsmanAger.getdefault ()//Get SMS Manager arraylist<string> texts=smsmanager.dividemessage (content)//To split the text message for ( String text:texts) {smsmanager.sendtextmessage (moble, NULL, text, NULL, NULL);
SMS Send}//Using spit Western prompts users to send successful Toast.maketext (Getapplicationcontext (), r.string.success, 1). Show ();
}
}
}
Add SMS Service privileges:
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" cn.itcast.action "
android:versioncode=" 1 "
android:versionname=" 1.0 ">
....
<USES-SDK android:minsdkversion= "8"/>
<!--SMS Service rights-->
<uses-permission android:name= " Android.permission.SEND_SMS "/>
</manifest>
I hope this article will help you with the Android program.