Easy Android Dialer

Source: Internet
Author: User

One, video notes:

1.

When the user clicks the app icon--

First create an app process--

Then create a main thread--

The main thread instantiates activity "NOTE: The OS will store information about the application (Context) into activity"--

Call OnCreate () "NOTE: An OS call, not a user call, is called only once during a life cycle"

2. Use of units

Text: SP

Non-text: DP (=DIP)

3.

When developing software, the content of the interface (. xml) is first written in a project.

Second, the Practice:

1. Interface:

The final layout to implement:

In Activity_main.xml:

1 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 android:orientation= "vertical"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6     <TextView7         Android:layout_width= "Match_parent"8 Android:layout_height= "Wrap_content"9 Android:text= "@string/mobile" />Ten      One     <EditText A         Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:id= "@+id/mobile" the         /> -      -     <Button -         Android:layout_width= "Wrap_content" + Android:layout_height= "Wrap_content" - Android:text= "@string/button"  + Android:id= "@+id/button" A         /> at  - </LinearLayout>

String.xml (For more internationalization):

<?XML version= "1.0" encoding= "Utf-8"?><Resources>    <stringname= "App_name">Phone Dialer</string>    <stringname= "Hello_world">Hello world!</string>    <stringname= "Action_settings">Settings</string>    <stringname= "mobile">Please enter your phone number</string>    <stringname= "button">Dial</string></Resources>

2. Request permission in the manifest file:

<?XML version= "1.0" encoding= "Utf-8"?><Manifestxmlns:android= "Http://schemas.android.com/apk/res/android" Package= "Com.example.phone"Android:versioncode= "1"Android:versionname= "1.0" >    <USES-SDKandroid:minsdkversion= "+"android:targetsdkversion= "+" />    <ApplicationAndroid:allowbackup= "true"Android:icon= "@drawable/ic_launcher"Android:label= "@string/app_name"Android:theme= "@style/apptheme" >        <ActivityAndroid:name=". Mainactivity "Android:label= "@string/app_name" >            <Intent-filter>                <ActionAndroid:name= "Android.intent.action.MAIN" />                <categoryAndroid:name= "Android.intent.category.LAUNCHER" />            </Intent-filter>        </Activity>    </Application><!--permissions: Google to protect the user's information security and privacy data, when using the relevant data, must request the relevant permissions, the software installation will appear the permission prompt -    <uses-permission  android:name= "Android.permission.CALL_PHONE"/ > </Manifest>

3. Code implementation:

Mainactivity.java:

 PackageCom.example.phone;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classMainactivityextendsActivity {PrivateEditText Mobiletext; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); Mobiletext=(EditText) Findviewbyid (r.id.mobile); Button Button= (Button) This. Findviewbyid (R.id.button); Button.setonclicklistener (NewButtonclicklistener ());//or use an anonymous inner class: New implements the interface's class object    }    //Internal classes: Heavy use, submission of software loading (to virtual machine) speed    Private Final classButtonclicklistenerImplementsView.onclicklistener {@Override Public voidOnClick (View v) {//the input parameter is the button object that is currently clicked//TODO auto-generated Method Stub//each time you click on the dial, the following sentence will use Findviewbyid to find the resource ID, resulting in time-consuming//EditText mobiletext = (EditText) Findviewbyid (r.id.mobile);String number =Mobiletext.gettext (). toString (); Intent Intent = new  Intent (); Intent.setaction ("Android.intent.action.CALL"); // intent.addcategory ("Android.intent.category.DEFAULT"); //            1 Code intent.setdata (Uri.parse ("Tel:" + number);  // The intent is passed to the OS, the OS discovers matching activity, activates startactivity (intent); // Note: Android.intent.category.DEFAULT is automatically added to the intent method internally, so the 1 code comment does not         }            }}

Easy Android Dialer

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.