【Android 开发教程】通过编码实现发送短信
来源:互联网 发布:看美剧网站推荐 知乎 编辑:程序博客网 时间:2024/05/16 06:02
本章节翻译自《Beginning-Android-4-Application-Development》,如有翻译不当的地方,敬请指出。
原书购买地址http://www.amazon.com/Beginning-Android-4-Application-Development/dp/1118199545/1. 创建工程,SMS。
2. 修改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" ><Button android:id="@+id/btnSendSMS" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Send SMS" android:onClick="onClick" /></LinearLayout>
3. 在AndroidManifest.xml中添加权限。
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.manoel.SMS" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="14" /> <uses-permission android:name="android.permission.SEND_SMS"/> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".SMSActivity" android:launchMode="singleTask" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>4. 在SMSActivity.java中添加一些测试代码。
public class SMSActivity extends Activity {/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);}public void onClick(View v) {sendSMS("130xxxxxxxx", "Hello my friends!");}//sends an SMS message to another deviceprivate void sendSMS(String phoneNumber, String message){SmsManager sms = SmsManager.getDefault();sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);}}5. 测试。
例子很简单,下面主要介绍发送短信的方法。
private void sendSMS(String phoneNumber, String message){SmsManager sms = SmsManager.getDefault();sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);}
首先获得SmsManager的对象,然后调用sendTextMessage接口。
- destinationAddress - 接收人的电话号码
- scAddress - 服务中心的地址,传入null使用默认的SMSC
- text - 短信的内容
- sentIntent - 当短信被发送,调用这个PendingIntet对象
- deliveryIntent - 当短信被送达,调用这个PendingIntent对象
- 【Android 开发教程】通过编码实现发送短信
- 【Android 开发教程】使用Intent发送短信
- [android开发]发送短信
- Android开发短信发送
- Android实现发送短信
- Android实现发送短信
- 【Android 开发教程】获取发送短信后的反馈
- Android开发系列(二):短信发送器的实现
- Android开发之短信发送
- android 开发 短信发送器
- Android开发之发送短信
- Android(开发):发送短信
- android开发 - 短信发送器
- Android开发《二》短信发送
- android实现发送短信demo
- android 定时发送短信实现
- android实现短信发送功能
- Android 实现发送短信demo
- OA项目之操作EXCEL导出数据报表的类
- 对360通讯录的反编译分析
- 计算机视觉牛人(最早在自动化所论坛上发现的)
- 如何看懂源码
- UltraEdit for Linux Keygen
- 【Android 开发教程】通过编码实现发送短信
- 20个势头最猛的开发者工具
- Linux中的hangcheck-timer模块
- poj 3211 Washing Clothes
- Linux下安装搜狗拼音输入法
- JNI函数
- 微软行业应用案例中心-九大行业、百份典型案例盘点
- [C/C++]_[判断程序是32位还是64位]
- HEVC compressGOP 接口