今天用到了打电话的功能,这要如何实现呢?
很简单
1.创建对应对的xml展示页面喝java文件
2.在manifest中添加权限
下面上代码吧:
这是布局的一部分
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="电话:123456789001"
android:id="@+id/more_phone"
android:background="#ff6666"
android:textSize="20dp"/>
在对应对的java代码绑定好控件以后下面就是正餐了:
在监听方法中使用
Intent intent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:"+phone_number));
这个语句就可以调用打电话的功能了。
public void onClick(View view) {
switch (view.getId()){
case R.id.more_phone:
String phone_number = phone.getText().toString();
Intent intent = new Intent(Intent.ACTION_CALL , Uri.parse("tel:"+phone_number));
startActivity(intent);
break;
当然还需要加一下权限:
在androidmainfest.xml中添加
这句就是大电话的权限了
转自我的个人博客:http://121.42.143.160/wordpress