1. In fact, it is a parameter setting for intent action.
Set the call permissions on the manifest herbal medicine:
1 < android:name= "Android.permission.CALL_PHONE"/>
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:orientation= "vertical"6 Tools:context=". Mainactivity " >7 8 <EditText9 Android:id= "@+id/phonenumber"Ten Android:layout_width= "Match_parent" One Android:layout_height= "Wrap_content" A Android:inputtype= "Phone" /> - - <Button the Android:id= "@+id/btn_call" - Android:layout_width= "Match_parent" - Android:layout_height= "Wrap_content" - Android:text= "Call" /> + - </LinearLayout>
Activity:
1 Public classMainactivityextendsActivity {2 3 PrivateEditText number;4 5 PrivateButton btn;6 7 @Override8 protected voidonCreate (Bundle savedinstancestate) {9 Super. OnCreate (savedinstancestate);Ten Setcontentview (r.layout.activity_main); OneNumber =(EditText) Findviewbyid (r.id.phonenumber); ABTN =(Button) Findviewbyid (r.id.btn_call); -Btn.setonclicklistener (NewOnclicklistener () { - the @Override - Public voidOnClick (View v) { - if(Number.gettext (). toString (). Trim (). Equals ("")) { -Number.seterror ("Phone number cannot be empty"); +}Else { - +Intent i =NewIntent ("Android.intent.action.CALL", the Uri A. Parse ("Tel:" +Number.gettext (). toString (). Trim ())); at startactivity (i); - } - - } - }); - in } -}
Android make phone small function