Inten tAction.CALL的使用,拨打电话
来源:互联网 发布:mac 远程 编辑:程序博客网 时间:2024/05/15 06:18
package EX05_02.txt;import java.util.regex.Matcher;import java.util.regex.Pattern;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class EX05_02 extends Activity {private Button mButton;private EditText mEditText; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initApp(); }private void initApp() {// TODO Auto-generated method stubmButton = (Button)findViewById(R.id.Button01);mEditText = (EditText)findViewById(R.id.EditText01);mButton.setOnClickListener(new Button.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubtry {String strInput = mEditText.getText().toString();if (isPhoneNumber(strInput) == true) {Intent mIntent = newIntent("android.intent.action.CALL", Uri.parse("tel:"+strInput));startActivity(mIntent);mEditText.setText("");} else {mEditText.setText("");Toast.makeText(EX05_02.this, "输入的电话格式不对", Toast.LENGTH_SHORT).show();}} catch (Exception e) {// TODO: handle exceptione.printStackTrace();}}private boolean isPhoneNumber(String phoneNumber) {// TODO Auto-generated method stubboolean isValid = false;String expression1 = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$";String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";CharSequence strInput = phoneNumber;Pattern pattern1 = Pattern.compile(expression1);Matcher matcher1 = pattern1.matcher(strInput);Pattern pattern2 = Pattern.compile(expression2);Matcher matcher2 = pattern2.matcher(strInput);if (matcher1.matches() | matcher2.matches()) {isValid = true;}return isValid;}});}}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="EX05_02.txt" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".EX05_02" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application><!-- 添加拨打电话权限 --><uses-permissionandroid:name = "android.permission.CALL_PHONE"/></manifest>
main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" ><EditText android:id="@+id/EditText01" android:layout_width="250dip" android:layout_height="wrap_content"></EditText><Button android:text="拨打电话" android:id="@+id/Button01" android:layout_width="100dip" android:layout_height="wrap_content"></Button></LinearLayout>
- Inten tAction.CALL的使用,拨打电话
- Action!Call拨打电话(Intent.ACTION.CALL的使用)
- [Android][M0][Call] 拨打电话
- 使用Intent拨打电话
- Android拨打电话Intent.ACTION.CALL
- Android拨打电话(Intent.ACTION.CALL)
- 拨打电话的礼仪
- 拨打电话的流程
- 拨打电话的程序
- 拨打电话的流程
- 简单的电话拨打
- Android -- make a phone call using Intent--使用意图拨打电话
- [FAQ12564]【Phone Call】双拨号键对应SIM卡拨打电话的实现
- 使用Android拨打电话功能
- 使用Android拨打电话功能
- 使用Android模拟器拨打电话
- Android使用Intent实现拨打电话的动作
- android电话拨打的实现
- u-boot for tiny210 ver3.1 (by liukun321咕唧咕唧)
- 改造Kindeditor之:自定义图片上传插件。 外加给图片增加水印效果的选择。
- 有效控制项目进度的几点技巧
- Android中measure过程、WRAP_CONTENT详解以及xml布局文件解析流程浅析(上)
- PostgreSQL基本操作
- Inten tAction.CALL的使用,拨打电话
- Hdu 1232 畅通工程
- yy笔试回忆
- You cannot combine custom titles with other title feature..
- 什麼是taxonomy, taxonomy access
- flashbuilder4 单选 RadioButton RadioButtonGroup
- 计数排序-基数排序
- C++程序设计体验
- 面向对象设计原则汇总