Android拨号器

移动开发 Android
智能机中常用的工具,希望这篇文章能帮到你!

1、界面效果图

 

2、AndroidManifest.xml

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
  3.    package="com.tjp" 
  4.    android:versionCode="1" 
  5.    android:versionName="1.0"> 
  6. <uses-sdk android:minSdkVersion="7" /> 
  7. <application android:icon="@drawable/congsmall" android:label="@string/app_name"> 
  8.    <activity android:name=".PhoneActivity" 
  9.              android:label="@string/app_name"> 
  10.          <intent-filter> 
  11.         <action android:name="android.intent.action.MAIN" />   
  12.         <category android:name="android.intent.category.LAUNCHER" /> 
  13.        </intent-filter>   
  14.       </activity> 
  15.     </application>   
  16.   <uses-permission android:name="android.permission.CALL_PHONE"/> 
  17. </manifest> 

注册电话拨打服务<uses-permission android:name="android.permission.CALL_PHONE"/>

3、界面代码

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
  3.      android:orientation="vertical" 
  4.      android:layout_width="fill_parent" 
  5.      android:layout_height="fill_parent" 
  6. > 
  7. <TextView 
  8.      android:layout_width="fill_parent" 
  9.      android:layout_height="wrap_content" 
  10.      android:text="@string/mobilelable" 
  11.  /> 
  12. <EditText 
  13.      android:layout_width="fill_parent" 
  14.      android:layout_height="wrap_content" 
  15.      android:id="@+id/mobile"/><Button 
  16.      android:layout_width="wrap_content" 
  17.      android:layout_height="wrap_content" 
  18.      android:text="@string/buttonlabl" 
  19.      android:id="@+id/btncall" 
  20. /> 
  21. </LinearLayout> 

4、界面值定义strings.xml

  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <resources>     
  3.     <string name="mobilelable">请输入手机号码</string>     
  4.     <string name="app_name">电话拨号器</string>      
  5.     <string name="buttonlabl">拨打</string> 
  6. </resources> 

5、activity

  1. package com.tjp;  
  2. import android.app.Activity;  
  3. import android.content.Intent;  
  4. import android.net.Uri;  
  5. import android.os.Bundle;  
  6. import android.view.View;  
  7. import android.widget.Button;  
  8. import android.widget.EditText;  
  9. public class PhoneActivity extends Activity {  
  10. private EditText mobile;  
  11. @Override  
  12. public void onCreate(Bundle savedInstanceState) {  
  13. super.onCreate(savedInstanceState);  
  14. setContentView(R.layout.main);  
  15. Button btncall=(Button)this.findViewById(R.id.btncall);  
  16. mobile=(EditText)this.findViewById(R.id.mobile);  
  17. btncall.setOnClickListener(new  View.OnClickListener(){  //匿名内部类  
  18.   @Override  
  19.   public void onClick(View v) {   
  20.     String mobilemobileText=mobile.getText().toString();  
  21.     Intent intent=new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+mobileText));//拨打电话                 
  22.     startActivity(intent);  
  23.    }  
  24.   });  
  25.  }  

【编辑推荐】

Android智能手机操作系统

深入理解Android消息处理系统原理

在Android应用程序中使用Internet数据

责任编辑:zhaolei 来源: 网络转载
相关推荐

2010-03-16 10:32:36

Java线程拨号器

2021-08-10 09:45:49

微软Windows 11Windows

2013-09-22 15:51:32

Android 4.4

2010-08-24 09:44:10

无线路由

2010-04-02 16:59:40

2009-12-22 15:04:11

路由器无法拨号故障

2010-03-26 18:27:25

无线拨号路由器

2009-12-29 09:18:46

2009-09-10 11:01:51

如何路由器设置自动拨号

2011-08-15 09:51:37

路由器PPPOE拔号

2010-08-12 09:24:14

华为路由器拨号互联

2009-11-10 10:43:42

2010-08-09 14:09:32

路由器互联

2010-04-09 14:35:03

无线路由器无法自动拨号

2010-08-25 11:04:28

路由器故障

2009-11-25 09:00:20

无线路由器自动拨号

2011-06-28 14:26:05

Opera浏览器

2009-12-10 17:12:58

2009-12-16 14:28:56

路由器配置

2009-11-16 09:50:59

点赞
收藏

51CTO技术栈公众号