1、要使用Android系统中的电话拨号功能,首先必须在AndroidManifest.xml功能清单中加入允许拨打电话的权限:

<uses-permission android:name="android.permission.CALL_PHONE" /> // 允许拨打电话权限

2、进行拨打电话的代码:

a、调用Android系统的拨号界面,但不发起呼叫,用户按下拨号键才会进行呼叫

 1 @Override   2    public void onCreate(Bundle savedInstanceState) {   3        super.onCreate(savedInstanceState);   4        setContentView(R.layout.main);   5           6        Button callBut = (Button)findViewById(R.id.callBut);   7           8        callBut.setOnClickListener(new View.OnClickListener() {   9           10         @Override  11         public void onClick(View v) {  12             Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel://13800138000"));  13             startActivity(intent);  14         }  15     });  16 }  

b、直接拨号发起呼叫

 1 @Override   2    public void onCreate(Bundle savedInstanceState) {   3        super.onCreate(savedInstanceState);   4        setContentView(R.layout.main);   5           6        Button callBut = (Button)findViewById(R.id.callBut);   7           8        callBut.setOnClickListener(new View.OnClickListener() {   9           10         @Override  11         public void onClick(View v) {  12             Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel://13800138000"));  13             startActivity(intent);  14         }  15     });  16 }  

注:其中Uri.parse("tel://13800138000")中的格式写成Uri.parse("tel:13800138000"),测试中也通过的。

3、拨号相关的知识点——Linkify的使用以及android:autoLink属性的使用,自动判断字符串是电话,网址或者邮件地址:

a、使用代码设置:

import android.text.util.Linkify;

Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES|Linkify.PHONE_NUMBERS);

b、在配置中设置: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、为你的电话拨号程序添加拨号键意图过滤器配置:

<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>// 当用户按下拨号键时,Android系统会弹出选择菜单让用户选择使用那个拨号器
<action android:name="android.intent.action.CALL_BUTTON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

<intent-filter> //功能跟上一个过滤器一样
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>

注:需要加上<category android:name="android.intent.category.BROWSABLE" />才能使调用的activity收到getIntent().getAction();

更多相关文章

  1. Android中shape的使用
  2. Android(安卓)startActivityForResult的使用
  3. Android(安卓)XML使用
  4. 【Android】解析Paint类中MaskFilter的使用
  5. CentOS64位系统使用Android虚拟机问题
  6. Android晋级之路
  7. 箭头函数的基础使用
  8. NPM 和webpack 的基础使用
  9. Python list sort方法的具体使用

随机推荐

  1. 无标题文章
  2. android 文本框实现搜索和清空效果
  3. Android(安卓)原生 MediaPlayer 和 Media
  4. android下载的进度条
  5. android 上层wifi模块调用分析
  6. android 定时器与Canvas结合使用
  7. android关闭或开启移动网络数据(关闭后,设
  8. android的crash log
  9. Ubuntu10.10上的Android开发环境搭建
  10. android 设置桌面背景