布局以及效果图片
代码
Strings.xml------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">day01_msm</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="phone_num">请输入手机号</string>
<string name="phone_center">请输入内容</string>
<string name="phone_btn">发送</string>
</resources>
--------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.day01_msm"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.WRITE_SMS"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.day01_msm.SmsActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
------------------------------------------------------------------------------------------------------------
package com.example.day01_msm;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SmsActivity extends Activity {
private Button button_viem;
private EditText edit_phone;
private EditText edit_sms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
button_viem = (Button) findViewById(R.id.phone_btn);
edit_phone = (EditText) findViewById(R.id.edit_num);
edit_sms = (EditText) findViewById(R.id.edit_center);
button_viem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
String phone_num = edit_phone.getText().toString();
String edit_content = edit_sms.getText().toString();
SmsManager smsManager = SmsManager.getDefault();
PendingIntent pendingIntent = PendingIntent.getBroadcast(
SmsActivity.this, 0, new Intent(), 0);
ArrayList<String> contents = smsManager.divideMessage(edit_content);
for (String c : contents) {
smsManager.sendTextMessage(phone_num, null, c, pendingIntent, null);
}
Toast.makeText(SmsActivity.this, "正在发送短信", Toast.LENGTH_LONG).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.sms, menu);
return true;
}
}