Android Development Learning--call app

Source: Internet
Author: User

Call app

SYSTEM/APP/PHONE.APK This is a call application, this Java API does not allow application-level programmers to rewrite, the system level can

system/app/dialer.apk This is a dialer app that can rewrite a third-party dialer

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

1 <LinearLayoutxmlns: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/activity_horizontal_margin"7 Android:paddingright= "@dimen/activity_horizontal_margin"8 Android:paddingtop= "@dimen/activity_vertical_margin"9 Tools:context=". Mainactivity "Ten android:orientation= "vertical" > One     <TextView A         Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" //component must be set to wide height, otherwise it cannot be compiled  - Android:text= "Please enter Number:" the         /> -     <EditText -         Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content"   + Android:id= "@+id/et"      -         /> +     <Button A          Android:layout_width= "Match_parent" at Android:layout_height= "Wrap_content"  - Android:text= "Dial"       - Android:id= "@+id/bt"If you want to manipulate a component in Java code, the component needs to set the ID so that it can be obtained by ID in the code -         /> -  - </LinearLayout>

Write source code in 2.SRC

1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidOnCreate (Bundle savedinstancestate) {//This method is called by the operating system when the app is created5         Super. OnCreate (savedinstancestate);6 Setcontentview (R.layout.activity_main); 7         //set the button to tap to listen8         //get the button object9Button BT =(Button) Findviewbyid (R.ID.BT); Ten         //Setting up monitoring OneBt.setonclicklistener (NewMyclick ()); A     } -  -     classMyclickImplementsonclicklistener{ the @Override -          Public voidOnClick (View arg0) { -             //TODO auto-generated Method Stub -System.out.print ("button was clicked"); +EditText et =(EditText) Findviewbyid (r.id.et); -String phone =Et.gettext (). toString (); +             //launch another app in one app and start the phone app in the dialer app
based on the action mechanism in the//android system,to invoke the application of the system, you tell the system what you want to do, the system will be able to do this action of the application to you, if there is no such application, will throw an exception
//Set actions to inform the system through intent
AIntent Intent =NewIntent (); at intent.setaction (Intent.action_call);//Set action, call -Intent.setdata (Uri.parse ("Tel:" +phone)); - startactivity (intent);//The intention to tell the system - } - - } in - to}

3. Add the permissions, in the manifest file, the bottom of the permission-add-usespermission-to the right of the name to select the appropriate permissions, in the code is automatically generated, as follows:

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

Runas--androidapplication, the results of the operation are as follows:

Add one point:

Event monitoring this is common.

Four ways to click events
First Kind
* Define a MyListener implementation Onclicklistener interface

Button BT1 = (button) Findviewbyid (R.ID.BT1);
Bt1.setonclicklistener (New MyListener ());

The second Kind
* Define an anonymous inner class implementation Onclicklistener interface

Button BT2 = (button) Findviewbyid (R.ID.BT2);
Bt2.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View v) {
System.out.println ("second type");

}
});

Third Kind
* Let current activity implement Onclicklistener interface

Button BT3 = (button) Findviewbyid (R.ID.BT3);
Bt3.setonclicklistener (this);

Fourth Type
* Set the OnClick property to the button node,

android:onclick= "click"

* Then define a method with the same name as the property value in activity

public void Click (View v) {
System.out.println ("fourth type");
}

Android Development Learning--call app

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.