Android应用开发---调用系统的打电话功能demo

本文介绍了一个简单的Android应用,该应用包含一个输入电话号码的EditText和一个拨打电话的Button。通过MainActivity.java文件中的代码实现了从EditText获取电话号码并进行拨号的功能。文章详细展示了界面布局及点击事件处理过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、界面设计(根本没设计)

一个EditView,一个Button,界面如右边图所示:

<RelativeLayout 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"
    tools:context=".MainActivity" >

    <EditText
        android:id="@+id/phoneNo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="49dp"
        android:ems="10" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/mobile"
        android:layout_alignRight="@+id/mobile"
        android:layout_below="@+id/mobile"
        android:layout_marginTop="50dp"
        android:text="call" />

</RelativeLayout>


二、代码实现


MainActivity.java


button.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				phoneText = (EditText) findViewById(R.id.phoneNo);
				String phoneno = phoneText.getText().toString();
				if (phoneno == null || "".equals(phoneno.trim())) {
					Toast.makeText(getApplicationContext(), "没有电话号码",
							Toast.LENGTH_SHORT).show();
				} else {
					Toast.makeText(getApplicationContext(), "有电话号码" + phoneno,
							Toast.LENGTH_SHORT).show();
					Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneno));
					startActivity(intent);
				}
			}
		});




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值