首页 > 系统 > Android > 正文

android快捷拨号

2019-11-09 13:53:55
字体:
来源:转载
供稿:网友

这是一个非常简单的小demo!ui截图:关键代码:打电话Intent intent = new Intent(Intent.ACTION_CALL);Uri data = Uri.parse("tel:" + "135xxxxxxxx");intent.setData(data);startActivity(intent);由于android真机中点击EditText会自动弹出软键盘,所以只需设置弹出为数字键盘即可:布局文件中EditText添加限定输入数字:android:digits="1234567890"java源码加入:etEditText.setInputType(EditorInfo.TYPE_CLASS_PHONE); 到此基本就可以实现快捷拨号与正常拨号了!java源码:package com.mrxu.phonecall;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.view.Window;import android.view.View.OnClickListener;import android.view.inputmethod.EditorInfo;import android.widget.EditText;import android.widget.ImageButton;public class MainActivity extends Activity implements OnClickListener{ImageButton bt_fq,bt_mq,bt_jl,bt_lb,bt_zs,bt_xt,bt_wg,bt_lz,bt_call;EditText etEditText;String num;@OverridePRotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//设置无标题栏this.requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);//定义组件etEditText=(EditText)findViewById(R.id.et_number);bt_fq=(ImageButton)findViewById(R.id.bt_fq);bt_mq=(ImageButton)findViewById(R.id.bt_mq);bt_jl=(ImageButton)findViewById(R.id.bt_jl);bt_lb=(ImageButton)findViewById(R.id.bt_lb);bt_zs=(ImageButton)findViewById(R.id.bt_zs);bt_xt=(ImageButton)findViewById(R.id.bt_xt);bt_wg=(ImageButton)findViewById(R.id.bt_wg);bt_lz=(ImageButton)findViewById(R.id.bt_lz);bt_call=(ImageButton)findViewById(R.id.bt_call);//设置按钮监听bt_fq.setOnClickListener(this);bt_mq.setOnClickListener(this);bt_jl.setOnClickListener(this);bt_lb.setOnClickListener(this);bt_zs.setOnClickListener(this);bt_xt.setOnClickListener(this);bt_wg.setOnClickListener(this);bt_lz.setOnClickListener(this);bt_call.setOnClickListener(this);etEditText.setInputType(EditorInfo.TYPE_CLASS_PHONE); }@Overridepublic void onClick(View v) {// TODO Auto-generated method stubswitch(v.getId()){case R.id.bt_fq://设置号码num="13814506801";//调用打电话call(num);break;case R.id.bt_mq:num="13675127803";call(num);break;case R.id.bt_lb:num="661588";call(num);break;case R.id.bt_xt:num="18757672238";call(num);break;case R.id.bt_zs:num="17757922610";call(num);break;case R.id.bt_wg:num="612813";call(num);break;case R.id.bt_lz:num="663002";call(num);break;case R.id.bt_jl:num="13868992331";call(num);break;case R.id.bt_call:num=etEditText.getText().toString();call(num);}}//打电话private void call(String number){if(number!=""){//设置意图为直接打电话Intent intent = new Intent(Intent.ACTION_CALL);//设置号码Uri data = Uri.parse("tel:" + number);intent.setData(data);//启动意图startActivity(intent);}}}demo源码这是我第一次写博客,从简单的开始写,写得不好敬请见谅!
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表