Android 笔记 day3

短信发送器

电脑弱爆了,开第二个emulater要10min!!!

顺便学会查看API文档

 1 package com.example.a11;
 2 
 3 import java.util.*;
 4 
 5 import android.app.Activity;
 6 import android.os.Bundle;
 7 import android.telephony.SmsManager;
 8 import android.view.Menu;
 9 import android.view.MenuItem;
10 import android.view.View;
11 import android.widget.*;
12 import android.view.*;
13 
14 public class MainActivity extends Activity {
15 
16     
17     private EditText numberText;
18     private EditText contentText;
19     @Override
20     protected void onCreate(Bundle savedInstanceState) {
21         super.onCreate(savedInstanceState);
22         setContentView(R.layout.activity_main);
23         
24         numberText=(EditText)this.findViewById(R.id.editText2);
25         contentText=(EditText)this.findViewById(R.id.editText1);
26         
27         Button button=(Button) this.findViewById(R.id.button);
28         button.setOnClickListener(new ButtonClickListener());
29         
30         
31     }
32     
33     private final class  ButtonClickListener implements View.OnClickListener {
34         @Override
35         public void onClick(View v) {
36             // TODO Auto-generated method stub
37             String number=numberText.getText().toString();
38             String content=contentText.getText().toString();
39             
40             SmsManager manager=SmsManager.getDefault();
41             ArrayList<String> texts= manager.divideMessage(content);
42             for(String text:texts){
43             manager.sendTextMessage(number, null, text, null, null);
44             }
45             
46             Toast.makeText(MainActivity.this, R.string.success, Toast.LENGTH_LONG).show();
47         }
48     }
49 
50     @Override
51     public boolean onCreateOptionsMenu(Menu menu) {
52         // Inflate the menu; this adds items to the action bar if it is present.
53         getMenuInflater().inflate(R.menu.main, menu);
54         return true;
55     }
56 
57     @Override
58     public boolean onOptionsItemSelected(MenuItem item) {
59         // Handle action bar item clicks here. The action bar will
60         // automatically handle clicks on the Home/Up button, so long
61         // as you specify a parent activity in AndroidManifest.xml.
62         int id = item.getItemId();
63         if (id == R.id.action_settings) {
64             return true;
65         }
66         return super.onOptionsItemSelected(item);
67     }
68     
69     
70     
71     
72     
73     
74     
75     
76 }
View Code

 

你可能感兴趣的:(Android 笔记 day3)