添加权限
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission><!-- 放在application标签之外-->
private Button mButton1;
private EditText mEditText1;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.telephone);
mEditText1 = (EditText) findViewById(R.id.editText1);
mButton1 = (Button) findViewById(R.id.button1);
/* 设定Button对象的OnClickListener来聆听OnClick事件 */
mButton1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
try {
/* 取得EditText中用户输入的字符串 */
String strInput = mEditText1.getText().toString();
/* 建构一个新的Intent并执行action.CALL的常数与透过Uri将字符串带入 */
Intent myIntentDial = new Intent(
"android.intent.action.CALL", Uri.parse("tel:"
+ strInput));
/* 在startActivity()方法中带入自定义的Intent对象以执行拨打电话的工作 */
startActivity(myIntentDial);
mEditText1.setText("");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
转跳至通讯录
1.添加权限
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
或者需要允许的权限
<uses-permission android:name="android.permission.CALL_PRIVILEGED"></uses-permission>
2.代码
Intent myIntentDial = new Intent("android.intent.action.CALL_BUTTON");
startActivity(myIntentDial);