android 5. callphone and sendsms
简单的实现两个模拟器的拨打电话与发送短信功能
主界面:
布局文件:
01 简单布局文件:
02
03 <?xml version="1.0" encoding="utf-8"?>
04 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
05 android:layout_width="fill_parent"
06 android:layout_height="fill_parent"
07 android:orientation="vertical" >
08
09 <TextView
10 android:layout_width="fill_parent"
11 android:layout_height="wrap_content"
12 android:inputType="phone"
13 android:numeric="decimal"
14 android:text="拨打电话" />
15
16 <EditText
17 android:id="@+id/phoneText"
18 android:layout_width="250dip"
19 android:layout_height="wrap_content"
20 android:hint="请输入电话号码..."
21 android:phoneNumber="true" />
22
23 <Button
24 android:id="@+id/callButton"
25 android:layout_width="wrap_content"
26 android:layout_height="wrap_content"
27 android:text="拨打" />
28
29 <TextView
30 android:layout_width="fill_parent"
31 android:layout_height="wrap_content"
32 android:text="发送短信" />
33
34 <EditText
35 android:id="@+id/smsText"
36 android:layout_width="250dip"
37 android:layout_height="120dip"
38 android:hint="请输入短信内容..." />
39
40 <Button
41 android:id="@+id/smsButton"
42 android:layout_width="wrap_content"
43 android:layout_height="wrap_content"
44 android:text="发送短信" />
45
46 </LinearLayout>
程序主要代码:
01 package smh.demo;
02
03 import android.app.Activity;
04 import android.app.PendingIntent;
05 import android.content.Intent;
06 import android.net.Uri;
07 import android.os.Bundle;
08 import android.telephony.SmsManager;
09 import android.view.View;
10 import android.view.View.OnClickListener;
11 import android.widget.Button;
12 import android.widget.EditText;
13 import android.widget.Toast;
14
15 public class IntentDemoActivity extends Activity {
16 /** Called when the activity is first created. */
17 private EditText phoneNumberText;
18
19 @Override
20 public void onCreate(Bundle savedInstanceState) {
21 super.onCreate(savedInstanceState);
22 setContentView(R.layout.main);
23
24 Button callButton = (Button) findViewById(R.id.callButton);
25 Button smsButton = (Button) findViewById(R.id.smsButton);
26
27 phoneNumberText = (EditText) findViewById(R.id.phoneText);
28
29 // 拨打电话
30 callButton.setOnClickListener(new OnClickListener() {
31
32 @Override
33 public void onClick(View arg0) {
34 String phoneNumber = phoneNumberText.getText().toString();
35
36 if (!"".equals(phoneNumber)) {
37 Intent intent = new Intent(Intent.ACTION_CALL, Uri
38 .parse("tel:" + phoneNumber));
39 startActivity(intent);
40 } else {
41 Toast.makeText(IntentDemoActivity.this, "对不起, 电话号码不能为空!",
42 Toast.LENGTH_LONG).show();
43 }
44 }
45 });
46
47 // 发送短信
48 sm
补充:移动开发 , Android ,