码迷,mamicode.com
首页 > 移动开发 > 详细

android 发送短信

时间:2014-07-17 14:01:05      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:android   blog   java   os   io   for   

所需权限<uses-permission android:name="android.permission.SEND_SMS" />

public class MessageActivity extends Activity {
	private EditText number;
	private EditText content;
	private Button button;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        number = (EditText) this.findViewById(R.id.number);
        content =  (EditText) this.findViewById(R.id.content);
        button = (Button) this.findViewById(R.id.button);
        
        button.setOnClickListener(ButtonOnClickListener);
    }
    
    private OnClickListener ButtonOnClickListener = new OnClickListener(){
		@Override
		public void onClick(View v) {
			String numberText = number.getText().toString();
			String contentText = content.getText().toString();
			
			SmsManager sms = SmsManager.getDefault();
			ArrayList<String> texts = sms.divideMessage(contentText);
			for(String t : texts){
				sms.sendTextMessage(numberText, null, t, null, null);
			}
			Toast.makeText(getApplicationContext(), R.string.success, Toast.LENGTH_LONG);
		}
    };
}

android 发送短信,布布扣,bubuko.com

android 发送短信

标签:android   blog   java   os   io   for   

原文地址:http://www.cnblogs.com/docomo/p/3850600.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!