1.AndroidManifest.xml 需要加的
<uses-permission android:name="android.permission.CALL_PHONE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
2.activity 中核心代码
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//call phone
phoneText = (EditText) this.findViewById(R.id.phone);//phone那个文本框
Button button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String phoneNumber = phoneText.getText().toString();//Editable
Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+phoneNumber));
PhoneMessageActivity.this.startActivity(intent);
}
});
//send message
messageText = (EditText)this.findViewById(R.id.message);
msPhoneText = (EditText) this.findViewById(R.id.messagePhoneNumber);
Button sendMessageButton = (Button) this.findViewById(R.id.send);
sendMessageButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
String messageContent = messageText.getText().toString();
String msPhoneNumber = msPhoneText.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
if(messageContent.length() > 70){
ArrayList<String> messages = smsManager.divideMessage(messageContent);
for(String content : messages){
smsManager.sendTextMessage(msPhoneNumber, null, content, null, null);
}
}else{
smsManager.sendTextMessage(msPhoneNumber, null, messageContent, null, null);
}
Toast.makeText(PhoneMessageActivity.this, "send succeed!", 1).show();
}
});
}