The Android system was originally designed for mobile phones, so it's very convenient to make a designated phone call in any app in the Android system.
The core is to use the intent jump, specifying that the request ACTION is Intent.action_call.
"Source Download" http://www.code4apk.com/android-code/178
The core code is as follows:
1
|
intent Intent =
new intent (Intent.action_call,uri.parse (
" tel:13888888888 "
);
|
This is accomplished by:
1th Step: Create a new 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);d Ialerbutton = (Button) Findviewbyid (R.id.button_dialer); Edittextphonenum = (EditText) Findviewbyid (r.id.edittext_phonenum);d Ialerbutton.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); }}); } }
2nd Step: Modify the configuration file: Main.xml
<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " > <textview android:id= "@+id/textview_phone" android:layout_width= "fill_parent" android:layout_height= "Wrap_ Content "android:text=" @string/tell_tile "/><edittext android:id=" @+id/edittext_phonenum "Android:layout_ Width= "Fill_parent" android:layout_height= "wrap_content"/> <button android:id= "@+id/Button_Dialer" Android: Layout_width= "100DP" android:layout_height= "wrap_content" android:text= "@string/button_call"/> </ Linearlayout>
3rd Step: Add dial-up support in configuration file Androidmanifest.xml
1
|
<
uses-permission android:name
=
" Android.permission.CALL_PHONE "
></
uses-permission
>
|
4th Step Debug Run:
Android Phone Call
Android Phone Call
"Source Download" http://www.code4apk.com/android-code/178