1. To use the phone dialing feature in Android, you must first include permission to make calls in the Androidmanifest.xml feature list:
<uses-permission android:name= "Android.permission.CALL_PHONE"/>//Allow call access
2, the code to make the call:
A, call the Android system Dial-up interface, but do not initiate the call, the user presses the dial key to make the call
1 @Override2 Public voidonCreate (Bundle savedinstancestate) {3 Super. OnCreate (savedinstancestate); 4 Setcontentview (R.layout.main); 5 6Button callbut =(Button) Findviewbyid (r.id.callbut); 7 8Callbut.setonclicklistener (NewView.onclicklistener () {9 Ten @Override One Public voidOnClick (View v) { AIntent Intent =NewIntent (Intent.action_dial, Uri.parse ("tel://13800138000")); - startactivity (Intent); - } the }); -}
B. Direct dialing to initiate a call
1 @Override2 Public voidonCreate (Bundle savedinstancestate) {3 Super. OnCreate (savedinstancestate); 4 Setcontentview (R.layout.main); 5 6Button callbut =(Button) Findviewbyid (r.id.callbut); 7 8Callbut.setonclicklistener (NewView.onclicklistener () {9 Ten @Override One Public voidOnClick (View v) { AIntent Intent =NewIntent (Intent.action_call, Uri.parse ("tel://13800138000")); - startactivity (Intent); - } the }); -}
Note: The format of Uri.parse ("tel://13800138000") is written in Uri.parse ("tel:13800138000"), which is also passed in the test.
3, the use of dial-related knowledge points--linkify and the use of Android:autolink attributes, automatically determine the string is the telephone, URL or e-mail address:
A. Use code settings:
Import android.text.util.Linkify;
Linkify.addlinks (TextView, linkify.web_urls| linkify.email_addresses| Linkify.phone_numbers);
b, set in configuration:android:autolink= "Web|phone|email"
<textview
Android:id= "@+id/tv1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:autolink= "Web|phone|email"
/>
4. Add the dialing key intent filter configuration for your Phone Dialer:
<activity android:name=. Callphoneactivity "
android:label= "@string/app_name";
<intent-filter>
<action android:name= "Android.intent.action.MAIN"/>
<category android:name= " Android.intent.category.LAUNCHER "/>
</intent-filter>
<intent-filter>//When the user presses the Dial key, the Android system pops up the Select menu to let the user choose to use that dialer
<action android:name= "Android.intent.action.CALL_BUTTON"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<intent-filter>//function as with a filter
<action android:name= "Android.intent.action.CALL_PRIVILEGED"/>
<category android:name= "Android.intent.category.DEFAULT"/>
<data android:scheme= "Tel"/>
</intent-filter>
Note: You need to add <category android:name= "Android.intent.category.BROWSABLE"/> To make the call activity receive Getintent (). Getaction () ;
Use Android to make phone calls