I have always been curious about the calls between mobile phones. I can call two mobile phones together. Today I can implement this small function. Otherwise, how can I study my Android mobile phone?
The Android mobile phone simulator comes with the dialing function. Let's first try the built-in dialing function. We started two simulators for Android 2.3.3. Do you notice that there is one in the upper left corner of each simulator, but the numbers are different? What exactly does this mean? Each simulator will be bound to the local IP Address "192.168.1.1", and "5556" is its port number, so the unique identifier of this simulator is: "192.168.1.1: 5556 ", so this port number can be regarded as our mobile phone number. As long as you understand this, you will not be confused "How to call without a mobile phone number ?"
Open the simulator where the mobile phone number is "5554", enter "mobile phone number" 5556, and click "dial key". The two mobile phones implement the call:
Next we will develop our own phone dialer.
● Create an android Development Project
Create a new project htcmobile and select Android 2.3.3. The project structure is as follows:
● Compile the strings. xml file
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> <string name = "hello"> Hello world, htcmobileactivity! </String> <string name = "app_name"> HTC dial </string> <string name = "mobile_name"> enter the mobile phone number </string> <string name = "call"> call this number </string> </resources>. This file is mainly used to define strings and values. ● compile main. the XML file is located in the Res/layout directory of the Project. <? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <textview Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: text = "@ string/mobile_name"/> <edittext Android: Id = "@ + ID/phoneno" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content"/> <button Android: Id = "@ + ID/cllphone" Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" Android: text = "@ string/call"/> </linearlayout>
This file mainly sets the layout file, similar to our HTML page file. In eclipse, We can click "graphical layout" in the file editing area to preview the effect:
● Compile the htcmobilemobileactivity. Java File
Packagecom. sinosoft; importandroid. app. activity; importandroid. content. intent; importandroid.net. uri; importandroid. OS. bundle; importandroid. view. view; importandroid. widget. button; import android. widget. edittext; publicclass htcmobileactivity extends activity {/** called when the activity is firstcreated. * // @ override public void oncreate (bundlesavedinstancestate) {super. oncreate (savedinstancestate); s Etcontentview (R. layout. main); super. oncreate (savedinstancestate); setcontentview (R. layout. main); button = (button) findviewbyid (R. id. cllphone); button. setonclicklistener (newview. onclicklistener () {public void onclick (viewv) {// todoauto-generated method stub edittextphonenotest = (edittext) findviewbyid (R. id. phoneno); // obtain the text box object stringphoneno = phonenotest. gettext (). tostring (); // obtain the input mobile phone number if (pH Oneno! = NULL )&&(! "". Equals (phoneno. trim () {intent = newintent (intent. action_call, Uri. parse ("Tel:" + phoneno); // Tel: Do not write an error in the prefix, used to create a call intention startactivity (intent ); // sending intent }}});}}
For more information, see notes.
● Apply for dialing permission
Because we call the dialer in the mobile phone system, we need to apply for the right to make a call, modify the androidmanifest. xml file, and add the following sentence:
<Uses-permissionandroid: Name = "android. Permission. call_phone"/>
As follows:
<?xml version="1.0"encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.sinosoft" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10"/> <uses-permission android:name="android.permission.CALL_PHONE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".HTCMobileActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Now, the preparation is complete. Run the project and enter the "mobile phone number" of another simulator in the simulator"
When you click the "Call this number" button, you will see the call with the built-in dial!
This is my learning result. You are welcome to repost it. Please feel free to share it with us. However, you must provide the link to this article at http://blog.csdn.net/youqishini/article/details/7379375 thank you ~