基本信息
源码名称:android 拨打电话例子源码(亲测可用)
源码大小:0.04M
文件格式:.rar
开发语言:Java
更新时间:2015-09-08
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

package androidCall.pack;

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 androidCall extends Activity {  
    /** Called when the activity is first created. */  
      
    private Button button;  
      
    private EditText text;  
      
      
      
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState);  
        setContentView(R.layout.main);  
          
        text = (EditText)findViewById(R.id.text);  
        button = (Button)findViewById(R.id.button);  
          
        button.setOnClickListener(new Button.OnClickListener(){  
  
            @Override  
            public void onClick(View v) {  
                // TODO Auto-generated method stub  
                try {  
                    String inputStr = text.getText().toString();  
                    if(isPhoneNumberValid(inputStr) == true){  
                        Intent myIntentDial = new Intent(  
                                Intent.ACTION_CALL,Uri.parse("tel:" inputStr)  
                        );  
                          
                        startActivity(myIntentDial);  
                          
                        text.setText("");  
                    }else{  
                        text.setText("");  
                        Toast.makeText(getBaseContext(), "电话格式不对", Toast.LENGTH_LONG).show();  
                    }  
                } catch (Exception e) {  
                    // TODO: handle exception  
                    System.out.println(e.getMessage());  
                }  
            }  
              
        });  
    }  
      
    public static boolean isPhoneNumberValid(String phoneNumber){  
          
        boolean isValid = false;  
        String expression = "^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{5})$";  
        String expression2 = "^\\(?(\\d{3})\\)?[- ]?(\\d{4})[- ]?(\\d{4})$";  
        CharSequence inputStr = phoneNumber;  
          
        Pattern pattern = Pattern.compile(expression);  
          
        Matcher matcher = pattern.matcher(inputStr);  
          
        Pattern pattern2 = Pattern.compile(expression2);  
          
        Matcher matcher2 = pattern2.matcher(inputStr);  
          
        if(matcher.matches()||matcher2.matches()){  
            isValid = true;  
        }  
          
          
        return isValid;  
          
    }  
}