5.模拟短信发送

代码实现模拟短信的发送。主要的操作步骤有:

//1.获取短信管理器

SmsManager sm = SmsManager.getDefault();
//2.发送短信
sm.sendTextMessage(phone, null, content, null, null);
模拟的代码如下

public class MainActivity extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
    }

    public void send(View v){
    	EditText et1 = (EditText) findViewById(R.id.et1);
    	EditText et2 = (EditText) findViewById(R.id.et2);
    	
    	String phone = et1.getText().toString();
    	String content = et2.getText().toString();
    	
    	//1.获取短信管理器
    	SmsManager sm = SmsManager.getDefault();
    	
    	//2.发送短信
    	//sm.sendTextMessage(phone, null, content, null, null);
    	//短信内容很长的时候分成几个发送
    	ArrayList<String> smss = sm.divideMessage(content);
    	
    	for(String string:smss){
    		sm.sendTextMessage(phone, null, string, null, null);
    	}
    	
    }


你可能感兴趣的:(5.模拟短信发送)