The Android system was originally designed for mobile phones. Therefore, it is very convenient to call a specified phone number in any android App.
The core is to use Intent jump, and specify the request Action as Intent. ACTION_CALL.
The core code is as follows:
1 |
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse(tel:13888888888); |
The following describes how to implement this function:
Step 2: Create an activity: DialerAndMsgActivity
package com.android.dev;import android.app.Activity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;public class DialerAndMsgActivity extends Activity { private Button dialerButton; private EditText editTextPhoneNum;/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);dialerButton = (Button) findViewById(R.id.Button_Dialer); editTextPhoneNum = (EditText) findViewById(R.id.EditText_PhoneNum);dialerButton.setOnClickListener(new View.OnClickListener(){public void onClick(View arg0) { Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse(tel:+ editTextPhoneNum.getText())); DialerAndMsgActivity.this.startActivity(intent); }}); } }
Step 2: modify the configuration file main. xml
Step 2: Add dialing support in the configuration file AndroidManifest. xml
1 |
<uses-permission android:name=android.permission.CALL_PHONE> uses-permission> |
4th trial run:
Android dialing
Android dialing
[Source code download] http://www.code4apk.com/android-code/178