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

Java-Android 之短信发送

时间:2014-11-05 17:07:23      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:android   blog   io   ar   os   java   for   sp   div   

file:///F:/workspace3/Android_ver2.5/src/cn/szy/com/MainActivity.java

package cn.szy.com;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    /** Called when the activity is first created. */
	private Button button;
	private EditText edittext,number;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        button =  (Button)this.findViewById(R.id.button);
        number = (EditText)this.findViewById(R.id.num);
        edittext = (EditText)this.findViewById(R.id.content);
    }
    
public void Opentall(View v){
	String num = number.getText().toString();
	String content = edittext.getText().toString();
	
	SmsManager manager = SmsManager.getDefault();
		
	ArrayList<String> texts = manager.divideMessage(content);
	
	for(String text : texts){
		manager.sendTextMessage(num, null, text, null, null);
	}
	Toast.makeText(MainActivity.this, "发送成功", Toast.LENGTH_LONG).show();

}
}

AndroidManifest.xml

<uses-permission android:name="android.permission.SEND_SMS"/>

 

Java-Android 之短信发送

标签:android   blog   io   ar   os   java   for   sp   div   

原文地址:http://www.cnblogs.com/sunxun/p/4076446.html

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