How do you want to add a dialing function to your app? Android provides two ways, one is action_call direct dial, the other is the action_dial way to open the system dial-up interface.
Let's do a little example here.
First, you need to add a permission to use the Androidmanifest.xml, this easy to forget haha.
<android:name= "Android.permission.CALL_PHONE"/>
Then take a simple interface test, here is the layout file code
<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "vertical" > <TextViewAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:text= "Please enter the number you want to dial:" /> <EditTextAndroid:id= "@+id/etphone"Android:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Phone" /> <ButtonAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:onclick= "Onclickactioncall"Android:text= "Action_call Way Direct dial" /> <ButtonAndroid:layout_width= "Fill_parent"Android:layout_height= "Wrap_content"Android:onclick= "Onclickactiondial"Android:text= "action_dial mode to open dial-up interface" /></LinearLayout>
The following is the corresponding activity code:
Packagechengyujia.androidtest;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.EditText;ImportAndroid.widget.Toast; Public classCallactivityextendsActivity {PrivateEditText Etphone; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_call); Etphone=(EditText) Findviewbyid (R.id.etphone); } //Action_call Way to call (direct call) Public voidOnclickactioncall (View v) {//the intent.action_call here is actually a specific string,//Action_call = "Android.intent.action.CALL",//tell the system I'm going to dial directly. Call (Intent.action_call); } //Action_dial Way to call (open Dial-up interface) Public voidonclickactiondial (View v) {//in the same vein, the intent.action_dial here is also a specific string//action_dial = "Android.intent.action.DIAL"//tell the system I want to open the dial-up interface, and to dial the number displayed on the Dial-up interface, the user decides whether to dial. Call (intent.action_dial); } Private voidCall (String action) {string phone=Etphone.gettext (). toString (); if(phone!=NULL&&phone.trim (). Length () >0){ //Here "Tel:" + phone number is a fixed format, the system a look at "Tel:" Beginning, you know the back should be the phone number. Intent Intent =NewIntent (Action, Uri.parse ("Tel:" +Phone.trim ())); StartActivity (intent);//call the above intent to implement dialing}Else{Toast.maketext ( This, "phone number cannot be empty", Toast.length_long). Show (); } }}
Run below to see the effect.
The interface is as follows:
I filled out the phone number 10086, below click the first button "Action_call Way direct dial",
As follows:
The discovery did not directly dial out, but gave the user a hint, let the user choose whether really to dial, this is also to prevent someone evil ah. Science and technology should make life better, not make life worse, but not everyone think so oh, so have to prevent AH. The system does the right, we continue to test, click "Allow once", began to really dial, as follows:
Hang up the phone, go back to the test interface, click the second button "action_dial mode to open the dial-up interface", following the click:
This is the system dial-up interface, at the same time to dial the number is also written to the user, or to dial it by the user decide.
In the actual development of which way, this depends on the specific situation. OK, let's write about the dialing function for Android apps.
Work is not the whole of life, finally put a funny joke, happy ah
Bodhi Old fathers will awaken to the body before: "You have learned to immortality and 72 change, today for the teacher to teach you new spells." "Wu Empty Road:" What is the spell? Bodhi old ancestral way: "See this cloud in the sky?" Here there are seven clouds, there are five clouds, a total of a few flowers? Goku answer: 12 roses. "Bodhi Lao zu Way:" Well, what I'm going to teach you is cloud computing. ”
Android app two ways to dial with programs