Android发送短信
来源:互联网 发布:unity3d的机械仿真 编辑:程序博客网 时间:2024/06/07 18:17
public class MainActivity extends Activity {
private EditText phoneNumber;
private EditText content ;
private Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumber = (EditText)this.findViewById(R.id.phoneNumber);
content = (EditText)this.findViewById(R.id.content);
send = (Button)this.findViewById(R.id.send);
send.setOnClickListener(new ButtonListener());
}
public class ButtonListener implements View.OnClickListener{
@Override
public void onClick(View v) {
String number = phoneNumber.getText().toString();
String contents = content.getText().toString();
SmsManager manager = SmsManager.getDefault();
ArrayList<String> texts = manager.divideMessage(contents);
for(String text : texts){
manager.sendTextMessage(number, null, text, null, null);
}
Toast.makeText(MainActivity.this, getResources().getString(R.string.success), 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.main, menu);
return true;
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/number" />
<EditText
android:id="@+id/phoneNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content" />
<EditText
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minLines="3"
/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sms"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="4"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.sms.MainActivity"
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>
<uses-permission
android:name="android.permission.SEND_SMS"
/>
</manifest>
- android 中发送短信
- android中发送短信
- android发送短信
- Android 发送短信
- Android自动发送短信
- Android发送短信
- android 发送短信sms
- android 发送短信
- android发送短信
- Android短信发送器
- android 之短信发送
- Android自动发送短信
- android短信发送
- Android发送短信
- android 发送短信问题
- android 短信发送程序
- Android发送短信
- Android短信发送程序
- The type javax.servlet.http.HttpServletRequest cannot be resolved
- 分布式数据库系统---商旅预定系统的实现(11)
- ubuntu 增加硬盘大小
- [概念]图形和图像的区别
- SQLServer中监视sql执行的时间,比较sql语句的效率
- Android发送短信
- 用python写1个简单的聊天服务器6-用户模型
- Chrome 如何访问手机站?
- 工作站服务没有启动 解决办法
- 服务器控件之间不能随意的嵌套
- Hibernate中Criteria的完整用法
- LINUX 常用命令集合
- 45个有新意的Photoshop教程和技巧
- Windows2008防火墙入站规则的设置浅议