This example describes the implementation of the Android Phone Dialer. Share to everyone for your reference. Specifically as follows:
The following cases simulate the implementation of the Android Phone Dialer
List of Androidmanifest.xml lists
<?xml version= "1.0" encoding= "Utf-8"?> <manifest xmlns:android=
"http://schemas.android.com/apk/res/" Android "
package=" Com.ljq.phone "
android:versioncode=" 1 "
android:versionname=" 1.0 ">
< Application android:icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name=
". Mainactivity "
android:label=" @string/app_name ">
<intent-filter>
<action android:name=" Android.intent.action.MAIN "/>
<category android:name=" Android.intent.category.LAUNCHER "/>"
</intent-filter>
</activity>
</application>
<uses-sdk android:minsdkversion = "7"/>
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
</manifest>
Main.xml Layout file:
<?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:layout_width=" fill_parent "android:layout_height=" Wrap_content "
android:text= "Please enter the phone number"/>
<edittext android:layout_width= "fill_parent"
android:layout_height= "Wrap_content"
android:id= "@+id/phone"/>
<button android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:text= "dial this number"
android:id= "@+id/button"/> </
Linearlayout>
Mainactivity class:
Package com.ljq.phone;
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 Mainactivity extends activity {private EditText phone=null;
@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Phone= (EditText) This.findviewbyid (R.id.phone);
Button button= (button) This.findviewbyid (R.id.button); Button.setonclicklistener (New View.onclicklistener () {public void OnClick (View v) {String tel=phone.gettext (). toSt
Ring ();
Method one, using Intent purpose: To activate the Android component//intent intent=new Intent ();
Intent.setaction ("Android.intent.action.CALL");
Intent.setdata (Uri.parse ("Tel:" +tel));
Method two Intent intent=new Intent ("Android.intent.action.CALL", Uri.parse ("Tel:" +tel)); The interior of the method automatically sets the category for the intent object: Android.intent.category.DEFAULT startactIvity (Intent);
}
});
}
}
Run Result:
Interface initialization:
Phone Dialing effect:
I hope this article will help you with your Android program.