Android dialing device and dialing device

Source: Internet
Author: User

Android dialing device and dialing device

Design of android Phone Dialer

 

Shows the running interface.

Procedure:

1. Create an Android project. In Eclipse, choose "File"> "NEW"> "Android Project"

2. Compile the string. xml file. The Code is as follows:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <resources> 3 4 <string name = "app_name"> Phone Dialer </string> 5 <string name = "hello_world"> Hello world! </String> 6 <string name = "action_settings"> Settings </string> 7 <string name = "mobile"> enter the mobile phone number: </string> 8 <string name = "button"> call </string> 9 10 </resources>View Code

3. Compile the main. xml file. The Code is as follows:

1 <RelativeLayout 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 = "com. example. phone. mainActivity $ PlaceholderFragment "> 10 <LinearLayout android: orientation =" vertical "11 android: layout_width =" fill_parent "12 android: layout_height =" fill_parent "> 13 <TextView14 android: layout_width = "fill_parent" 15 android: layout_height = "wrap_content" 16 android: text = "@ string/mobile" 17/> 18 <EditText 19 android: layout_width = "fill_parent" 20 android: layout_height = "wrap_content" 21 android: id = "@ + id/phoneNum"/> 22 <Button 23 android: layout_width = "wrap_content" 24 android: layout_height = "wrap_content" 25 android: text = "@ string/button" 26 android: id = "@ + id/btnPhone"/> 27 </LinearLayout> 28 </RelativeLayout>View Code

4. Click the event to process the button. The Code is as follows:

1 package com. example. phone; 2 3 import android. app. activity; 4 import android. app. fragment; 5 import android. content. intent; 6 import android.net. uri; 7 import android. OS. bundle; 8 import android. view. layoutInflater; 9 import android. view. menu; 10 import android. view. menuItem; 11 import android. view. view; 12 import android. view. viewGroup; 13 import android. widget. button; 14 import android. widget. editTe Xt; 15 16 public class MainActivity extends Activity {17 18 @ Override19 protected void onCreate (Bundle savedInstanceState) {20 super. onCreate (savedInstanceState); 21 setContentView (R. layout. activity_main); 22 23 if (savedInstanceState = null) {24 getFragmentManager (). beginTransaction () 25. add (R. id. container, new PlaceholderFragment ()). commit (); 26} 27} 28 29 @ Override30 public boolean onCreateOptions Menu (Menu menu) {31 32 // Inflate the menu; this adds items to the action bar if it is present.33 getMenuInflater (). inflate (R. menu. main, menu); 34 return true; 35} 36 37 @ Override38 public boolean onOptionsItemSelected (MenuItem item) {39 // Handle action bar item clicks here. the action bar will40 // automatically handle clicks on the Home/Up button, so long41 // as you specify a parent activity in AndroidManifest. xml.42 int id = item. getItemId (); 43 if (id = R. id. action_settings) {44 return true; 45} 46 return super. onOptionsItemSelected (item); 47} 48 49/** 50 * A placeholder fragment containing a simple view.51 */52 public static class PlaceholderFragment extends Fragment {53 54 public PlaceholderFragment () {55} 56 57 @ Override58 public View onCreateView (LayoutInflater inflater, ViewGroup co Ntainer, 59 Bundle savedInstanceState) {60 View rootView = inflater. inflate (R. layout. fragment_main, container, 61 false); 62 63 final EditText phoneText = (EditText) rootView. findViewById (R. id. phoneNum); 64 Button btnPhone = (Button) rootView. findViewById (R. id. btnPhone); 65 btnPhone. setOnClickListener (new View. onClickListener () {66 67 @ Override68 public void onClick (View v) {69 // TODO Auto-generated method Stub70 String phoneNum = phoneText. getText (). toString (); 71 if (phoneNum! = Null &&(! "". Equals (phoneNum. trim () 72 {73 Intent intent = new Intent (Intent. ACTION_CALL, Uri. parse ("tel:" + phoneNum); 74 startActivity (intent); 75} 76} 77}); 78 return rootView; 79} 80} 81 82}View Code

5. Apply for the dialing permission. You need to apply for permissions in the AndroidManifest. xml file of the function list. Add the <uses-permission> code after the </application> label as follows:

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <manifest xmlns: android = "http://schemas.android.com/apk/res/android" 3 package = "com. example. phone "4 android: versionCode =" 1 "5 android: versionName =" 1.0 "> 6 7 <uses-sdk 8 android: minSdkVersion =" 14 "9 android: targetSdkVersion = "19"/> 10 11 <application12 android: allowBackup = "true" 13 android: icon = "@ drawable/ic_launcher" 14 android: label = "@ string/app_name" 15 android: theme = "@ style/AppTheme"> 16 <activity17 android: name = "com. example. phone. mainActivity "18 android: label =" @ string/app_name "> 19 <intent-filter> 20 <action android: name =" android. intent. action. MAIN "/> 21 22 <category android: name =" android. intent. category. LAUNCHER "/> 23 </intent-filter> 24 </activity> 25 </application> 26 <uses-permission android: name =" android. permission. CALL_PHONE "/> 27 </manifest>View Code

 

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.