再次:编写代码
package com.sharpandroid.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 SharpPhoneActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View e) {
// 获取手机号
EditText phonenoText = (EditText) findViewById(R.id.phoneno);
String phoneno = phonenoText.getText().toString();
if ((phoneno != null) && (!"".equals(phoneno.trim()))) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri
.parse("tel:" + phoneno));
startActivity(intent);
}}});}}
最后在AndroidManifest.xml的配置文件中添加以下粗体字代码
< xml version="1.0" encoding="utf-8" >
package="com.sharpandroid.phone" android:versionCode="1"
android:versionName="1.0">