Android development and learning-call applications and call android Development

Source: Internet
Author: User

Android development and learning-call applications and call android Development

 

Call Application

System/app/phone.apk: this is a call application. This Java API cannot be rewritten by application programmers.

System/app/dialer.apk: This is a dialer application. You can override a third-party dialer.

 

1. Define the layout in the res-layout-activity_main.xml:

1 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 2 xmlns: tools = "http://schemas.android.com/tools" 3 android: layout_width = "match_parent" 4 android: layout_height = "match_parent" 5 android: paddingBottom = "@ dimen/activity_vertical_margin" 6 android: paddingLeft = "@ dimen/users" 7 android: paddingRight = "@ dimen/activity_horizontal_margin" 8 android: paddingTop = "@ dimen/activity_vertical_margin" 9 tools: context = ". mainActivity "10 android: orientation =" vertical "> 11 <TextView12 android: layout_width =" wrap_content "13 android: layout_height =" wrap_content "// the width and height of the widget must be set, otherwise, 14 android: text = "cannot be compiled. Enter the number:" 15/> 16 <EditText 17 android: layout_width = "match_parent" 18 android: layout_height = "wrap_content" 19 android: id = "@ + id/et" 20/> 21 <Button22 android: layout_width = "match_parent" 23 android: layout_height = "wrap_content" 24 android: text = "dial" 25 android: id = "@ + id/bt" // if you want to operate a component in java code, you must set the id of the component, in this way, the component 26/> 27 28 </LinearLayout> can be obtained through the id in the code.

2. Write source code in src

1 public class MainActivity extends Activity {2 3 @ Override 4 protected void onCreate (Bundle savedInstanceState) {// this method is called by the operating system when the App is created. 5 super. onCreate (savedInstanceState); 6 setContentView (R. layout. activity_main); 7 // click listen for Button settings 8 // get the Button object 9 Button bt = (Button) findViewById (R. id. bt); 10 // set listening 11 bt. setOnClickListener (new Myclick (); 12} 13 14 class Myclick implements OnClickListener {15 @ Override16 public void onClick (View arg0) {17 // TODO Auto-generated method stub18 System. out. print ("button clicked"); 19 EditText et = (EditText) findViewById (R. id. et); 20 String phone = et. getText (). toString (); 21 // start another application in one application, and start the call application in the dial Application
// The Android system calls the system application based on the action mechanism. If you tell the system what action you want to perform, the system will apply the action to you, if this application is not available, an exception is thrown.
// Set the action to inform the System of the intention
22 Intent intent = new Intent (); 23 intent. setAction (Intent. ACTION_CALL); // sets the action and calls 24 intent. setData (Uri. parse ("tel:" + phone); 25 startActivity (intent); // inform the System of the intent 26} 27 28} 29 30 31}

3. add the permission. In the configuration file, select the appropriate permission for the name on the Right of permission-add-UsesPermission-under, which will be automatically generated in the code, as shown below:

<Uses-permission android: name = "android. permission. CALL_PHONE"/>

 

 

RunAs -- AndroidApplication:

 

 

Add:

Event listening is common

Four ways to write click events
First
* Define a MyListener to implement the onClickListener interface.

Button bt1 = (Button) findViewById (R. id. bt1 );
Bt1.setOnClickListener (new MyListener ());

Second
* Define an anonymous internal class to implement the onClickListener Interface

Button bt2 = (Button) findViewById (R. id. bt2 );
Bt2.setOnClickListener (new OnClickListener (){

@ Override
Public void onClick (View v ){
System. out. println ("Type 2 ");

}
});

Third
* Enable the current activity to implement the onClickListener Interface

Button bt3 = (Button) findViewById (R. id. bt3 );
Bt3.setOnClickListener (this );

Fourth
* Set the onClick attribute for the Button node,

Android: onClick = "click"
 
* Then define the method with the same name as the property value in the activity.

Public void click (View v ){
System. out. println ("fourth ");
}

 

Related Article

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.