PhoneActivity.java

        
  1. publicclassPhoneActivityextendsActivityimplementsOnClickListener{
  2. /**
  3. *Button呼出电话按钮
  4. */
  5. privateButtonbtn_callon;
  6. /**
  7. *EditText号码输入框
  8. */
  9. privateEditTextet_phoneNum;
  10. /**
  11. *String用户输入电话号码字符串
  12. */
  13. privateStringphoneNum;
  14. /**Calledwhentheactivityisfirstcreated.*/
  15. @Override
  16. publicvoidonCreate(BundlesavedInstanceState){
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.main);
  19. initView();
  20. btn_callon.setOnClickListener(this);
  21. }
  22. /**
  23. *初始化界面:获取组件
  24. */
  25. publicvoidinitView(){
  26. btn_callon=(Button)findViewById(R.id.btn_id_phone_callon);
  27. et_phoneNum=(EditText)findViewById(R.id.et_id_phone_phoneNum);
  28. }
  29. publicvoidonClick(Viewv){
  30. phoneNum=et_phoneNum.getText().toString();
  31. if(phoneNum!=null&&!"".equals(phoneNum.trim())){//判断手机号是否为空
  32. Intentintent=newIntent(Intent.ACTION_CALL,Uri.parse("tel:"//把tel前缀传给系统之后,操作系统会自动调用拨号服务来拨打该号码
  33. +phoneNum));
  34. startActivity(intent);
  35. }
  36. }
  37. }

main.xml

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <LinearLayoutxmlns: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. <TextView
  7. style="@style/wrap_content"
  8. android:text="@string/tv_text_phone_phonetext"/>
  9. <EditText
  10. android:id="@+id/et_id_phone_phoneNum"
  11. style="@style/fill_parent"
  12. android:inputType="number"
  13. android:singleLine="true"/>
  14. <Button
  15. android:id="@+id/btn_id_phone_callon"
  16. style="@style/wrap_content"
  17. android:text="@string/btn_text_phone_callon"/>
  18. </LinearLayout>

strings.xml

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <resources>
  3. <stringname="tv_text_phone_phonetext">请输入电话号码:</string>
  4. <stringname="btn_text_phone_callon">呼出电话</string>
  5. <stringname="app_name">Phone</string>
  6. </resources>

style.xml

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <resources>
  3. <stylename="wrap_content">
  4. <itemname="android:layout_width">wrap_content</item>
  5. <itemname="android:layout_height">wrap_content</item>
  6. </style>
  7. <stylename="fill_parent">
  8. <itemname="android:layout_width">fill_parent</item>
  9. <itemname="android:layout_height">wrap_content</item>
  10. </style>
  11. </resources>

AndroidManifest.xml

        
  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <manifestxmlns:android="http://schemas.android.com/apk/res/android"
  3. package="com.fisnail"
  4. android:versionCode="1"
  5. android:versionName="1.0">
  6. <uses-sdkandroid:minSdkVersion="8"/>
  7. <!--拨打电话权限-->
  8. <uses-permissionandroid:name="android.permission.CALL_PHONE"/>
  9. <application
  10. android:icon="@drawable/ic_launcher"
  11. android:label="@string/app_name">
  12. <activity
  13. android:name=".PhoneActivity"
  14. android:label="@string/app_name">
  15. <intent-filter>
  16. <actionandroid:name="android.intent.action.MAIN"/>
  17. <categoryandroid:name="android.intent.category.LAUNCHER"/>
  18. </intent-filter>
  19. </activity>
  20. </application>
  21. </manifest>

更多相关文章

  1. Android的第一个应用(拨打电话)
  2. Android 重力感应选号码
  3. android 如何调用系统拨打电话的功能
  4. android 电话状态的监听
  5. Android电话Phone设计框架介绍
  6. Android tesseract-orc之扫描身份证号码
  7. Android电话系统之-rild
  8. Android 利用广播实现黑名单【指定号码】的短信的拦截 附源码下
  9. 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、

随机推荐

  1. Android中bluetooth的架构
  2. Android(安卓)activity与service中的子线
  3. Eclipse如何打包生成Apk安装包实例(图)
  4. [android架构篇]mvp+rxjava+retrofit+eve
  5. Android(安卓)Aidl 机制
  6. Platform Dependent Compilation 多平台
  7. Android连接、断开蓝牙扫描枪时屏幕刷新
  8. 如何在Android中实现悬浮Activity
  9. Android中adb端口被占用的有效解决方案
  10. Android(安卓)记录一次 代码重启设备的爬