Function implementation: A EditView A dial button, enter the number to jump to the dial-up interface
Interface layout: Activity_call.xml
//Linear vertical layout: One editview text, one button
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:orientation= "vertical"6 Android:paddingbottom= "@dimen/activity_vertical_margin"7 Android:paddingleft= "@dimen/activity_horizontal_margin"8 Android:paddingright= "@dimen/activity_horizontal_margin"9 Android:paddingtop= "@dimen/activity_vertical_margin"Ten Tools:context=". Phoneactivity " > One A <TextView - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" the Android:text= "Please enter the phone" /> - - <EditText - Android:id= "@+id/edittext1" + Android:layout_width= "Fill_parent" - Android:layout_height= "Wrap_content" + Android:inputtype= "Phone" /> A at <Button - Android:id= "@+id/callsumbit" - Android:layout_width= "Wrap_content" - Android:layout_height= "Wrap_content" - android:layout_gravity= "Center" - Android:text= "Call" /> in - </LinearLayout>
Create method for Callactivity
1 protected voidonCreate (Bundle savedinstancestate) {2 Super. OnCreate (savedinstancestate);3 Setcontentview (r.layout.activity_call);4Button BTN =(Button) Findviewbyid (r.id.callsumbit);5Btn.setonclicklistener (NewOnclicklistener () {6 7 @Override8 Public voidOnClick (View v) {9EditText Etnumber =(EditText) Findviewbyid (R.ID.EDITTEXT1);Ten OneString number =Etnumber.gettext (). toString (); AIntent Intent =NewIntent (); - intent.setaction (intent.action_call); -Intent.setdata (Uri.parse ("Tel:" +Number )); the startactivity (intent); - } - }); -}
Increase access to calls: Androidmanifest.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Manifestxmlns:android= "Http://schemas.android.com/apk/res/android"3 Package= "Com.ccec.callphone"4 Android:versioncode= "1"5 Android:versionname= "1.0" >6 7 <USES-SDK8 android:minsdkversion= "8"9 android:targetsdkversion= "+" />Ten <uses-permissionAndroid:name= "Android.permission.CALL_PHONE"/> One A <Application - Android:allowbackup= "true" - Android:icon= "@drawable/ic_launcher" the Android:label= "@string/app_name" - Android:theme= "@style/apptheme" > - <Activity - Android:name= "Com.ccec.callphone.CallActivity" + Android:label= "@string/app_name" > - <Intent-filter> + <ActionAndroid:name= "Android.intent.action.MAIN" /> A at <categoryAndroid:name= "Android.intent.category.LAUNCHER" /> - </Intent-filter> - </Activity> - </Application> - - </Manifest>
Dial-up functionality can now be implemented.
Simple implementation of Android dialer