Android电话拨号
package cn.jinyejun.androiddail; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.support.v7.app.ActionBarActivity; import android.telephony.SmsManager; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends ActionBarActivity implements android.view.View.OnClickListener { private Button btnCall = null; private Button btnSend = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnCall = (Button) this.findViewById(R.id.btn_dail); btnCall.setOnClickListener(this); btnSend = (Button) this.findViewById(R.id.btn_send); btnSend.setOnClickListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } private void callNumber() { EditText etNumber = (EditText) this.findViewById(R.id.et_number); String number = etNumber.getText().toString().trim(); Intent intent = new Intent(); intent.setAction(Intent.ACTION_CALL); intent.setData(Uri.parse("tel:" + number)); startActivity(intent); } private void sendMessage(){ EditText etNumber = (EditText) this.findViewById(R.id.et_number); String number = etNumber.getText().toString().trim(); EditText etContent = (EditText)this.findViewById(R.id.et_content); String content = etContent.getText().toString().trim(); SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, content, null, null); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_dail: callNumber(); break; case R.id.btn_send: sendMessage(); break; default: break; } } }
相关推荐
huha 2020-10-16
xfcyhades 2020-11-20
sgafdsg 2020-11-04
Michael 2020-11-03
fengyeezju 2020-10-14
ziyexiaoxiao 2020-10-14
业余架构师 2020-10-09
OuNuo0 2020-09-29
moses 2020-09-22
Angelia 2020-09-11
qinxu 2020-09-10
刘炳昭 2020-09-10
Nostalgiachild 2020-09-07
Nostalgiachild 2020-08-17
leavesC 2020-08-14
一青年 2020-08-13
AndroidAiStudy 2020-08-07
ydc0 2020-07-30
绿豆饼 2020-07-28