Android简单的发短信案例
来源:互联网 发布:动态图截取软件 编辑:程序博客网 时间:2024/04/30 22:02
import java.util.List;
import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class SmsActivity extends Activity {
private Button sendBtn;
private EditText etPhone;
private EditText etSms;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 设置显示的视图
setContentView(R.layout.main);
// 初始化组件对象
sendBtn = (Button) findViewById(R.id.sendBtn);
etPhone = (EditText) findViewById(R.id.etphone);
etSms = (EditText) findViewById(R.id.etsms);
// 注册按钮的点击事件
sendBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// 获取电话号码
Editable phone = etPhone.getText();
// 获取短信内容
Editable sms = etSms.getText();
// 发送短信
// 要使用短信的管理器
SmsManager smsManager = SmsManager.getDefault();
// 声明一个意图
PendingIntent pendingIntent = PendingIntent.getBroadcast(
SmsActivity.this, 0, new Intent(), 0);
Log.v("TAG",sms.toString().length()+"");
if (sms.toString().length() > 70 ) {
Log.v("TAG", sms.toString());
//拆分的时候 并没有拆分 smsManager 本身 默认的大小 多少个字符
List<String> content = smsManager.divideMessage(sms
.toString());
for (String str : content) {
Log.v("TAG", str);
smsManager.sendTextMessage(phone.toString(), null, str,
pendingIntent, null);
}
} else {
// 管理器对象 进行发送短信
smsManager.sendTextMessage(phone.toString(), null,
sms.toString(), pendingIntent, null);
// 要干事情 需要这个干这个事情的权限
}
Toast.makeText(SmsActivity.this, "短信成功", Toast.LENGTH_LONG).show();
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<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="fill_parent"
android:layout_height="wrap_content"
android:text="@string/etcallphone" />
<EditText
android:id="@+id/etphone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone" >
<requestFocus />
</EditText>
<CheckedTextView
android:id="@+id/checkedTextView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/etSms" />
<EditText
android:id="@+id/etsms"
android:layout_width="match_parent"
android:layout_height="82dp"
android:layout_weight="0.19"
android:ems="10"
android:inputType="textMultiLine" />
<Button
android:id="@+id/sendBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/sendBtn" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, SmsActivity!</string>
<string name="app_name">Sms</string>
<string name="etcallphone">请输入的电话号码</string>
<string name="etSms">请输入短信内容</string>
<string name="sendBtn">发送</string>
</resources>
- Android简单的发短信案例
- Android中简单的发短信应用
- android之简单发短信
- Android拨打电话和发短信的简单程序
- 向android模拟器打电话发短信的简单方法
- 向Android模拟器打电话发短信的简单方法
- 向android模拟器打电话发短信的简单方法
- 发短信案例
- android发短信的代码
- 简单的发短信,难不倒程序员
- Android中发短信的代码
- 发短信的小例子(Android)
- Android的打电话发短信功能实例
- 【Android】打电话与发短信的实现
- (转)向android模拟器打电话发短信的简单方法
- android打电话,发短信
- android打电话,发短信
- android 打电话 发短信
- Oracle设置语录
- jQuery Media多媒体插件下载与个性化配置详解
- 从Web到移动应用的设计思维转换
- JVM调优总结(一)-- 一些概念
- 博客网址
- Android简单的发短信案例
- MVC学习
- [Leetcode] Partition List
- C#位运算 http://www.cnblogs.com/sweting/archive/2009/11/05/1596873.html
- JVM调优总结(二)-一些概念
- 07 - 基本控件:ListView 列表
- 多线程信号量控制
- DBUnit向mysql导数据异常
- Oracle存储过程