Android怎么实现打电话源码

作者:活力源 | 创建时间: 2023-03-18
Android怎么实现打电话源码,Andriod打电话源码及其可运行程序,Android开发环境搭建好,这里介绍一个简单的开发打电话的功能...
Android怎么实现打电话源码

操作方法

Activity对应的xml的布局 <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"    android:paddingBottom="@dimen/activity_vertical_margin"    android:paddingLeft="@dimen/activity_horizontal_margin"    android:paddingRight="@dimen/activity_horizontal_margin"    android:paddingTop="@dimen/activity_vertical_margin"    tools:context=".MainActivity" > <EditText        android:id="@+id/telNo"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignParentLeft="true"        android:layout_alignParentTop="true"        android:layout_marginLeft="25dp"        android:layout_marginTop="26dp" /> <Button        android:id="@+id/btn"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_alignLeft="@+id/telNo"        android:layout_below="@+id/telNo"        android:layout_marginTop="37dp"        android:text="Button" /> </RelativeLayout>

主项目里面的Activity里面的方法,注意,添加命名空间 @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_main);    Button btn = (Button)findViewById(R.id.btn);  final EditText phoneNoText = (EditText)findViewById(R.id.telNo);                 btn.setOnClickListener(new View.OnClickListener() {             public void onClick(View arg0) {                   String telNo = phoneNoText.getText().toString();          if((telNo!=null)&&(!"".equals(telNo.trim()))){           Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+telNo));           startActivity(intent);     }     }     });                  }

在AndroidManifest.xml里面修改关键部分。 <uses-permission android:name="android.permission.CALL_PHONE"/> 上述功能是准许用户,可以执行,拨号功能,这是必不可少的,没有的话,会包异常,不能正常运行应用程序。

如下图,所示,结果,攻大家参考

温馨提示

Android怎么实现打电话源码
点击展开全文

更多推荐