1、
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cn.itcast.phone"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MainActivity"
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-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.CALL_PHONE"/>
</manifest>
2、
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="button">拔打此号码</string>
</resources>
3、
package cn.itcast.phone;
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;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button)this.findViewById(R.id.button);// js: getElementById();
//button.setOnClickListener(new ButtonClickListener());
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
EditText mobileText = (EditText)findViewById(R.id.mobile);
String mobile = mobileText.getText().toString();//得到了用户输入的手机号
Intent intent = new Intent("android.intent.action.CALL", Uri.parse("tel:"+ mobile));
startActivity(intent);
}
});
}
/*
private final class ButtonClickListener implements View.OnClickListener{
public void onClick(View v) {
EditText mobileText = (EditText)findViewById(R.id.mobile);
String mobile = mobileText.getText().toString();//得到了用户输入的手机号
Intent intent = new Intent("android.intent.action.CALL", Uri.parse("tel:"+ mobile));
startActivity(intent);
}
}*/
}