Android 拨号界面和直接拨打电话界面代码控制
//定义TAG为空
private static final String TAG = null;
//定义Button的点击事件
tell.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
/* Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+10086));
startActivity(intent);*/
//直接拨打
String tel = "10086";
call(tel);
}
});
//点击事件调用的类
protected void call(String tel) {
/* // 只进入拨号界面,不拨打
Uri uri = Uri.parse("tel:" + tel);
Intent intent = new Intent(Intent.ACTION_DIAL, uri);
startActivity(intent); */
//直接拨打
Log.d(TAG, "call:" + tel);
Uri uri = Uri.parse("tel:" + tel);
Intent intent = new Intent(Intent.ACTION_CALL, uri);
startActivity(intent);
}
注意: 添加权限:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS"/>