android短信发送

添加权限:

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

 核心代码:

private void sendMessage() {
		String phoneNumber = txtPhoneNumber.getText().toString().trim() ; 
		String message = txtMessageContent.getText().toString();
		if(TextUtils.isEmpty(phoneNumber)||TextUtils.isEmpty(message)){
			Toast.makeText(getApplicationContext(), "手机号码或短信内容不能为空!", Toast.LENGTH_SHORT).show(); 
			return ; 
		}
		SmsManager smsManager = SmsManager.getDefault() ; 
		ArrayList<String> messages = smsManager.divideMessage(message) ; 
		for(String curMessage:messages){
			smsManager.sendTextMessage(phoneNumber, null, curMessage, null, null) ; 
		}
		Toast.makeText(getApplicationContext(), "短信已发送!", Toast.LENGTH_SHORT).show(); 
	}

 

你可能感兴趣的:(android)