二、android的短信发送器
来源:互联网 发布:64位系统装32位mysql 编辑:程序博客网 时间:2024/06/04 19:11
1、工程结构:
效果图:
2、AndroidManifest.xml配置文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="cn.huangjie.sms" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".MainActivity" > <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>
3、main.xml布局管理文件
<?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/number" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/numberEdit" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/content"/> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" android:minLines="3" android:id="@+id/contentEdit" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/button" android:id="@+id/button" /></LinearLayout>
4、strings.xml数值管理文件
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, MainActivity!</string> <string name="app_name">Sms</string> <string name="number">请输入手机号码</string> <string name="content">请输入短信内容</string> <string name="button">发送</string> <string name="sucess">发送成功</string></resources>
5、R.java资源类文件
/* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */package cn.huangjie.sms;public final class R { public static final class attr { } public static final class drawable { public static final int ic_launcher=0x7f020000; } public static final class id { public static final int button=0x7f050002; public static final int contentEdit=0x7f050001; public static final int numberEdit=0x7f050000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int button=0x7f040004; public static final int content=0x7f040003; public static final int hello=0x7f040000; public static final int number=0x7f040002; public static final int sucess=0x7f040005; }}
6、窗口及其时间处理
package cn.huangjie.sms;import java.util.ArrayList;import android.app.Activity;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;public class MainActivity extends Activity { private EditText numberText;private EditText contentText; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); numberText = (EditText)findViewById(R.id.numberEdit); contentText = (EditText)findViewById(R.id.contentEdit); Button button = (Button)findViewById(R.id.button); button.setOnClickListener(new SmsOnClickListener()); } private final class SmsOnClickListener implements View.OnClickListener{public void onClick(View v) {String number = numberText.getText().toString();String content = contentText.getText().toString();//取得默认的短信管理器对象SmsManager manager = SmsManager.getDefault();//第一个是短信要发往的号码 //第二个是短信中心的号码,输入null代表使用系统默认的短信中心号码 //第三个一条短信通常只允许发送七十个汉字,一旦超过限制,要拆分成几条发送出去 //第四个用于得到发送的状态 //第五个用于对方是否收到这条短信的状态 //四和五这两个参数都是需要移动网络返回电信号来知道的,所以这个方法的内部采用异步的方式来处理 //这个行为,一旦该方法api的内部根据返回的电信号对外发送出一个广播,然后把结果存放在广播里面 //使用广播接受者就可以接收到这个广播,得到发送的状态和对方是否收到的状态,如不要返回则传递nullArrayList<String> texts = manager.divideMessage(content);for(String text : texts){manager.sendTextMessage(number, null, text, null, null);}//所谓的上下文就是与应用有关的,这些信息在整个应用的范围内都可以被访问到的.例如应用的包名 //MainActivity也可以当作一个上下文的对象,因为它的顶级父类是一个上下文对象Context//也可以使用getApplicationContext()或者使用MainActivity.thisToast.makeText(getApplicationContext(), R.string.sucess, Toast.LENGTH_LONG);} } }
工程下载路径:
- 二、android的短信发送器
- Android开发系列(二):短信发送器的实现
- Android学习系列(二): 短信发送器
- 二、短信发送器
- Android开发《二》短信发送
- android的短信发送
- Android android下的短信发送器
- Android短信发送器
- android 短信发送器
- android短信发送器
- Android短信发送器
- android短信发送器
- android 短信发送器
- Android短信发送器
- Android -- 短信发送器
- android 短信发送器
- Android短信发送器
- android短信发送器
- Java NIO框架Netty教程(四) – ServerBootStrap启动流程源码分析
- android 自定义圆角ImageView以及锯齿的处理
- hdu1114Piggy-Bank(DP完全背包)
- Mysql命令操作-用户
- exe文件打开方式变成记事本无法运行
- 二、android的短信发送器
- CUDA dynamic parallelism在 visual studio 2010 中的设置
- CODE 4: Sum Root to Leaf Numbers
- 数据结构复习之【排序】
- Linux内核进程调度schedule深入理解
- codeforces round 176Div1 B
- JavaScript 秘密花园
- 九大排序算法再总结
- Eclipse好用快捷键