Use Android to make phone calls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.