android系统发送短信息代码
来源:互联网 发布:菲律宾网络彩票合法吗 编辑:程序博客网 时间:2024/05/16 05:23
1.首先搭建Activity界面,
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/tv_tip_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/tv_tip_phone" />
<EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_tip_phone"
android:inputType="phone"
/>
<TextView
android:id="@+id/tv_tip_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/et_phone"
android:text="@string/tv_sms"
/>
<EditText
android:id="@+id/et_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_tip_sms"
android:minLines="4"
android:inputType="text"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/et_sms"
android:layout_marginTop="54dp"
android:text="@string/btn_send_sms" />
</RelativeLayout>
2.添加权限
<!-- 拨打电话权限 -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<!-- 发送短息权限 -->
<uses-permission android:name="android.permission.SEND_SMS" />
3.编写代码:
public class SmsActivity extends Activity {
private EditText tv_phone;
private EditText tv_sms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
tv_phone= (EditText)findViewById(R.id.tv_tip_phone);
tv_sms= (EditText)findViewById(R.id.tv_tip_sms);
}
private void CallSms(View v) {
// TODO Auto-generated method stub
String phone = tv_phone.getText().toString();
String sms = tv_sms.getText().toString();
if (TextUtils.isEmpty(phone)) {
Toast.makeText(this, "请输入电话号码!", Toast.LENGTH_LONG).show();
if(TextUtils.isEmpty(sms)){
Toast.makeText(this, "请输入电话号码!", Toast.LENGTH_LONG).show();
}else{
SmsManager smsManager = SmsManager.getDefault();
List<String> smsMessages = smsManager.divideMessage(sms);
for(String smsmg:smsMessages){
smsManager.sendTextMessage(phone, null, smsmg,null, null);
Toast.makeText(this, "发送成功",Toast.LENGTH_LONG).show();
}
}
}
}
}
- android系统发送短信息代码
- tc351i 发送短信息 代码
- Android实现短信息发送
- 短信息发送
- 短信息发送
- 短信息发送
- Android发送信息模拟系统
- Android SmsManager(短信管理器),发送短信息
- cmpp发送超长短信息
- cmpp发送超长短信息
- Visual C#发送短信息
- cmpp发送超长短信息
- cmpp发送超长短信息
- cmpp发送超长短信息
- PDU格式发送短信息
- smsManager.sendTextMessage() 发送短信息
- Android 发送短息
- Android获取系统信息代码
- 专业知识点总结(补充版)
- UVA 10023 - Square root(手算平方根)
- js基础(2)
- Objectice-C之类层次结构
- gradle cache转为local Maven库,解决gradle编译依赖包时常被墙
- android系统发送短信息代码
- RTPS流媒体简介
- IOS用CGContextRef画各种图形(文字、圆、直线、弧线、矩形、扇形、椭圆、三角形、圆角矩形、贝塞尔曲线、图片)
- 开始写博客咯
- 无言的叹息
- ubuntu 12.04下访问windows共享文件夹
- Quick-Cocos2d-x 触摸机制详解
- Linux 下 strace的妙用,追踪应用程序使用了哪些所谓的“数据库”文件
- Oracle Enterprise Linux下安装Oracle