输入一个电话号码,如果是正常的号码就调用拨号面板,否则显示错误。
package zhang.IntentFilter;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.telephony.PhoneNumberUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class intentFilter extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bCall = (Button) findViewById(R.id.Button01);
bCall.setOnClickListener( // 内部监听接口
new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
EditText eTel = (EditText) findViewById(R.id.myEditText);
String StrTel = eTel.getText().toString();// 取得输入的值
if (PhoneNumberUtils.isGlobalPhoneNumber(StrTel)) {
Intent intent = new Intent(Intent.ACTION_DIAL, Uri
.parse("tel://" + StrTel));
intentFilter.this.startActivity(intent);
} else {
Toast.makeText(intentFilter.this,
"the phonenumber is error form", 5000).show();
}
}
});
}
}
<?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/myEditText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/tel" />
<Button
android:id="@+id/Button01"
android:textSize="24dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/call" />
</LinearLayout>