Joke Collection Website - Public benefit messages - Can't Android handheld terminals make phone calls and send text messages?
Can't Android handheld terminals make phone calls and send text messages?
This case uses a simple communication tool to consolidate the activity of android, the layout of LinearLayout, basic control buttons, making phone calls and sending text messages, and applying the intention of interactive communication. This case focuses on the principle of event handling in android and its application in the project.
2 case introduction
The zero-distance communication tool can realize the function of sending text messages and making phone calls. No matter where you are, you only need to communicate with friends and family at zero distance, so that your life will be zero distance from now on.
3 case study
This project is developed with android2.3.3, because this project mainly realizes the functions of making phone calls and sending short messages, so we use intentional phone calls and short messages to activate the program. In the Intentional calling program used in this paper, the behavior of Intent is ACTION_DIAL, and the phone number of the called party is transmitted in intent. There are two keys to making phone calls. First, add uses-permission to the AndroidManifest, and declare the rights of Android: name = "android.permission.call _ phone". Because calling belongs to the underlying service of mobile phone, it is closely related to topics such as user privacy and call cost. Therefore, the program must be licensed. Secondly, by customizing the Intent object, the key "ACTION_CALL" is brought in, and the telephone number (data) entered by the user is brought in by the method of Uri.parse (), and finally it is completed by the method of startActivity (). To realize the SMS function, you must use the SMS permission in the android system, that is, add the following contents to AndoridManifest.xml
& ltuses-permissionandroid:name = " Android . permission . send _ SMS "/& gt;
4 case design
When you click the "Send SMS" and "Call" buttons, the event handling process is as follows:
(1) Create event sources for the Send SMS and Call buttons.
(2) The event source is registered with the click event listener class.
(3) When the "Send SMS" and "Call" buttons of the event source are clicked, the event is triggered, and the onClick(View) method in the event listener class is called to handle the business logic.
5 Business logic design
if(myeditText.getText()。 length()>; 0{
My intention = new intention (intention. ACTION_CALL,uri . parse(" tel:"+my edit text . gettext()。 toString()));
phone . this . start activity(my intent);
}
string mobile = my edittext . gettext()。 toString();
string content = edit text 2 . gettext()。 toString();
SMS manager SMS = SMS manager . get default();
pending Intent sent Intent = pending Intent . get broadcast(SMS activity . this,0,new Intent(),0);
First come to the renderings:
Zazie Hoko
6 case realization:
Some important codes implemented in the case are as follows:
1. Home Interface
& lt? Xml version =" 1.0 "encoding ="utf-8"? & gt
& ltrelative layout xmlns:Android = "/apk/RES/Android "
Android:layout _ width = " fill _ parent "
Android:layout _ height = " fill _ parent "
Android:background = " @ drawable/BG "
Android:orientation = " vertical " & gt;
& lt buttons
android:id="@+id/button 1 "
Android:layout _ width = " wrap _ content "
Android:layout _ height = " wrap _ content "
Android:layout _ alignParentBottom = " true "
Android:layout _ alignParentLeft = " true "
Android:layout _ margin bottom = " 165 DP "
Android:layout _ margin left = " 23dp "
Android:background = " @ drawable/button "
Android:text = " Call "/& gt;
& lt buttons
android:id="@+id/button2 "
Android:layout _ width = " wrap _ content "
Android:layout _ height = " wrap _ content "
Android:layout _ alignBaseline = " @+id/button 1 "
Android:layout _ align bottom = " @+id/button 1 "
Android:layout _ alignParentRight = " true "
Android:background = " @ drawable/button "
Android:text= "Send SMS"
2. Main interface activities
Public class SmsAndPhoneActivity extends Activity {
/* * Called when an activity is first created. */
Button 1, button2
@ Overlay
public void on create(Bundle saved instancestate){
super . oncreate(savedInstanceState);
setContentView(r . layout . main);
//Find the corresponding control according to the ID.
Button 1 =(Button)findViewById(r . id . Button 1);
Button 2 =(Button)findViewById(r . id . Button 2);
//button to listen for the event.
button 1 . setonclicklistener(new OnClickListener(){
@ Overlay
Public void onClick (view v)
// TODO automatically generated method stub
//Jump to the phone page.
Intent Intent = new Intent(smsandphoneactivity . this,
phone . class);
StartActivity (intention);
}
});
button 2 . setonclicklistener(new OnClickListener(){
@ Overlay
Public void onClick (view v)
// TODO automatically generated method stub
//Jump to SMS page
Intent intention1= new intention (SmsAndPhoneActivity.this,
SMS activity . class);
start activity(intent 1);
}
});
}
}
3.SMS interface activities
Public class SmsActivity extension Activity{
@ Overlay
public void on create(Bundle saved instancestate){
super . oncreate(savedInstanceState);
setContentView(r . layout . SMS);
Button butsend =(Button)findViewById(r . id . butsend);
final EditText my EditText =(EditText)findViewById(r . id . mobile);
final EditText EditText 2 =(EditText)findViewById(r . id . content);
but send . setonclicklistener(new OnClickListener(){
@ Overlay
Public void onClick (view v)
// TODO automatically generated method stub
string mobile = my edittext . gettext()。 toString();
string content = edit text 2 . gettext()。 toString();
SMS manager SMS = SMS manager . get default();
pending intent sent intent = pending intent . get broadcast(SMS activity . this,
0,new Intent(),0);
Try {
if(content . length()& gt; 70)
{
List & lt string & gtmsgs=sms.divideMessage (content);
For (string message: msgs)
{
sms.sendTextMessage(mobile,null,msg,sentintent,null);
}
}
other
{
sms.sendTextMessage(mobile,null,content,sentintent,null);
}
Catch (exception e) {
// TODO: Handling exception
e . printstacktrace();
}
Toast. Maketext (SMS activity. Well, "SMS sent successfully", 1000). show();
}
});
4. Call interface activity
Open class telephone promotion activities {
@ Overlay
public void on create(Bundle saved instancestate){
super . oncreate(savedInstanceState);
setContentView(r . layout . phone);
final EditText my EditText =(EditText)findViewById(r . id . my EditText);
Button but phone =(Button)findViewById(r . id . but phone);
but phone . setonclicklistener(new OnClickListener(){
@ Overlay
Public void onClick (view v)
// TODO automatically generated method stub
if(myeditText.getText()。 length()>; 0)
{
My intention = new intention (intention. Action call, Uri.parse
(" tel:"+myeditText.getText()。 toString()));
phone . this . start activity(my intent);
}
}
});
}
}
Source download: SmsAndPhone.zip
- Related articles
- How do you get the pieces of heavenly sword and Hailing Moby Dick?
- There are many Android phones, how to receive the verification code remotely?
- Is the nucleic acid result positive? What happened? Will the client be notified immediately when the nucleic acid result is positive?
- How to find the lost SMS icon? Come in and have a look.
- Watch out for telecom fraud propaganda slogan (60 sentences collection)
- Vietnam Ant Group Refund Notification SMS
- Copy of birthday wishes for friends
- How to inquire about your mortgage information?
- How to recover Huawei mate mobile phone short message by mistake?
- I received a short message yesterday morning, saying that my mobile phone number won the prize in the lottery where I was a singer. There is a website on the text message saying that I follow the prom