Android 电话拔号
package com.eboy.phone;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText text = null;
private Button btn1 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.button);
text = (EditText) findViewById(R.id.edittext);
btn1.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener {
public void onClick(View v) {
String number = text.getText().toString();
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:" + number));
startActivity(intent); //方法内部会自动为intent添加类别: android.intent.category.DEFAULT
}
}
}
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
private EditText text = null;
private Button btn1 = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn1 = (Button)findViewById(R.id.button);
text = (EditText) findViewById(R.id.edittext);
btn1.setOnClickListener(new ButtonClickListener());
}
private final class ButtonClickListener implements View.OnClickListener {
public void onClick(View v) {
String number = text.getText().toString();
Intent intent = new Intent();
intent.setAction("android.intent.action.CALL");
intent.setData(Uri.parse("tel:" + number));
startActivity(intent); //方法内部会自动为intent添加类别: android.intent.category.DEFAULT
}
}
}