|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1.拨号器所需要的权限的配置
- <uses-permission android:name="android.permission.CALL_PHONE"/>
复制代码 2.拨号器布局的配置:
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MainActivity" >
- <EditText
- android:id="@+id/phone"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:hint="输入电话号码"
- android:inputType="number"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="拨号"
- android:onClick="call"
- />
- </LinearLayout>
复制代码 如图:
3.在activity中编写拨号程序:
- package com.example.callphone_test;
- import android.net.Uri;
- import android.os.Bundle;
- import android.app.Activity;
- import android.content.Intent;
- import android.view.Menu;
- import android.view.View;
- import android.widget.EditText;
- public class MainActivity extends Activity {
- private EditText phoneText;
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
- phoneText = (EditText) this.findViewById(R.id.phone);
- }
-
- public void call(View v)
- {
- String number = phoneText.getText().toString().trim();
- //打开系统呼叫
- Intent intent = new Intent();
- intent.setAction(Intent.ACTION_CALL); //与系统拨号中的action进行匹配
- intent.setData(Uri.parse("tel://" + number)); //设置拨号的Uri
- startActivity(intent); //跳转到系统的拨号器上面
- }
- }
复制代码
|
|