Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限

一:布局文件先设计拨号器的简单界面,可以先用画图软件构思 界面

   二 :Activity中进行获取EditText中的电话号码,然后点击,使用Intent(意图)进行实现打电话的功能

          Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile));

   三:注意必须在AndroidManifset,xml文件进行打电话的权限设置 

    

核心源代码 (包自己去引)

[java]  view plain copy print ?
  1. public class PhoneDuanXINActivity extends Activity {  
  2.     private EditText mobileText;             //在这里写个成员变量,就可以直接调用  
  3.       
  4.       
  5.     @Override  
  6.     public void onCreate(Bundle savedInstanceState) {  
  7.         super.onCreate(savedInstanceState);  
  8.         setContentView(R.layout.main);  
  9.         mobileText = (EditText)this.findViewById(R.id.mobile);    //调用成员变量mobileText   强转给右边  
  10.        
  11.         // 使用匿名类进行加监听    
  12.         Button button = (Button)this.findViewById(R.id.button);  
  13.         button.setOnClickListener(new View.OnClickListener(){         
  14.             public void onClick(View v){  
  15.                   
  16.                 String mobile = mobileText.getText().toString();  //得到了用户输入的手机号  
  17.                 Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+ mobile ));  //意图    Intent(行为, 行为数据)   intent类用于描述一个应用将会做什么事          在windos中就有种东西  开始菜单》》运行》》 http://www.baidu.com    它可以直接打开,这是为什么?   是因为浏览器   认出了http:   
  18.                 startActivity(intent); //这就是内部类访问外部类的实例  
  19.             }  
  20.         });  
  21.     }  
  22. }  

strings.xml

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="hello">下午好</string>  
  4.     <string name="app_name">摩托罗拉手机 拨号器</string>  
  5.     <string name="mobile">请输入号码</string>  
  6.     <string name="button">拨打</string>  
  7. </resources>  

main.xml

[html]  view plain copy print ?
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="fill_parent"  
  4.     android:layout_height="fill_parent"  
  5.     android:orientation="vertical" >  
  6.   
  7.     <TextView          
  8.         android:layout_width="fill_parent"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="@string/mobile"  
  11.          />  
  12.     <EditText         
  13.         android:layout_width="fill_parent"  
  14.         android:layout_height="wrap_content"  
  15.         android:id = "@+id/mobile"        
  16.      />  
  17.     <Button  
  18.         android:layout_width ="wrap_content"  
  19.         android:layout_height="wrap_content"  
  20.         android:text = "@string/button"  
  21.         android:id = "@+id/button"  
  22.         />  
  23.         
  24.           
  25.          
  26. <p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; text-align: left; "><span style="font-family: 'Microsoft YaHei'; color: rgb(102, 102, 102); "><span style="font-size:13px;">如图所示这三个控件是垂直摆放的,所以要使用线性布局来搁置显示控件</span></span></p><p style="color: rgb(51, 51, 51); font-family: Arial; line-height: 26px; text-align: left; "><strong><span style="font-family: 'Microsoft YaHei'; color: rgb(102, 102, 102); "><span style="font-size:13px;">效果图:</span></span></strong></p>  
  27. </LinearLayout>  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值