Android学习笔记_2_发送短信
来源:互联网 发布:logo字体发表软件 编辑:程序博客网 时间:2024/04/25 23:45
1、首先需要在AndroidManifest.xml文件中加入发送短信的权限
<uses-permission android:name="android.permission.SEND_SMS"/>
2、使用相对布局方式进行布局
hint:表示编辑框的提示信息
layout_below:在那个视图的下方
<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" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tvPhone" android:id="@+id/tv1" /> <EditText android:id="@+id/editPh" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/tv1" android:layout_below="@+id/tv1" android:hint="@string/phoneMsg" android:ems="10" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/editPh" android:layout_below="@+id/editPh" android:text="@string/tvSMS" /> <EditText android:id="@+id/etSMS" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:ems="10" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/etSMS" android:layout_below="@+id/etSMS" android:text="@string/send" /></RelativeLayout>
3、string的资源文件
<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">SMS</string> <string name="action_settings">Settings</string> <string name="tvPhone">请输入手机号</string> <string name="tvSMS">请输入短信内容</string> <string name="success">发送成功</string> <string name="fail">发送失败</string> <string name="phoneMsg">Please a phone number</string> <string name="send">发送</string></resources>
4、activity类的实现
public class MainActivity extends Activity { private EditText etPhone; private EditText etSMS; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); etPhone = (EditText)this.findViewById(R.id.editPh);//号码 etSMS = (EditText)this.findViewById(R.id.etSMS);//短信内容 Button btnSend = (Button)this.findViewById(R.id.button1); //注册事件 btnSend.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { String phone = etPhone.getText().toString(); String sms = etSMS.getText().toString(); SmsManager manager = SmsManager.getDefault(); //如果短信太长,就分割开来在进行发送 ArrayList<String> msgs = manager.divideMessage(sms); for (String msg : msgs) { manager.sendTextMessage(phone, null, msg, null, null); } //参数分别表示上下文对象,显示消息,停留时间长短 Toast.makeText(MainActivity.this, 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; }}
0 0
- Android学习笔记_2_发送短信
- Android(OPhone) 学习笔记 - 短信发送
- android学习笔记3--------------短信发送器
- 学习笔记7-Android短信发送器
- Android 短信发送接收笔记
- Android学习笔记(5)---模拟手机发送短信
- Android学习笔记---08_短信发送器的制作
- Android源码学习笔记1-短信发送流程分析
- Android学习笔记(2)——短信发送器
- 【Android】安卓学习笔记之发送短信
- Android基础学习 - 发送短信:
- android学习 -- 短信发送器
- android学习笔记短信
- Android入门笔记之发送短信
- 笔记 - Android - 2.短信发送器
- Android学习之短信发送器
- android sdk--- 发送短信实例学习
- Android学习文档之秘密发送短信
- jdbc连接各种数据库字符串
- Mysql跨数据库(在同一IP地址中)复制表
- PS快捷键和常用小知识
- 本地变量与环境变量
- Android学习笔记_1_拨打电话
- Android学习笔记_2_发送短信
- C++ 内联函数示例
- ocx开发经验
- Android学习笔记_3_四种布局
- Android学习笔记_4_单元测试
- 通过反射操作泛型
- Android学习笔记_5_文件操作
- Tomcat+Oracle配置连接池的例子
- 正则表达式通解2