短信发送器
来源:互联网 发布:英文期刊数据库 编辑:程序博客网 时间:2024/05/18 02:42
继上一课讲的电话拨打器,这节讲的是短信发送器。
布局比较简单,如下所示:
activity_main.xml
<LinearLayout 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:orientation="vertical" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="手机号码" /> <EditText android:id="@+id/phone" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="短信内容:" /> <EditText android:id="@+id/content" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送信息"/></LinearLayout>
主程序文件:
MainActivity.java
package com.example.smstools;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.telephony.SmsManager;import android.view.View;import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity {EditText phone = null;EditText content = null;Button button = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);phone = (EditText) findViewById(R.id.phone);content = (EditText) findViewById(R.id.content);button = (Button) findViewById(R.id.button);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {String num = phone.getText().toString();String smsContent = content.getText().toString();SmsManager manager = SmsManager.getDefault();// 获取短信管理器manager.sendTextMessage(num, null, smsContent, null, null);// 发送短信}});}}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.smstools" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> <uses-permission android:name="android.permission.SEND_SMS"/> <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.smstools.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
和上例一样,最后要记得添加权限: <uses-permission android:name="android.permission.SEND_SMS"/>,因为比较简单也就不加过多的说明,不懂的话,可以参考下上例电话拨打器。
运行效果如下:
- 短信发送器
- Android短信发送器
- 短信发送器
- android 短信发送器
- android短信发送器
- 二、短信发送器
- 短信发送器
- 短信发送器2
- Android短信发送器
- 短信发送器
- android短信发送器
- android 短信发送器
- Android短信发送器
- 短信发送器
- Android -- 短信发送器
- android 短信发送器
- Android短信发送器
- android短信发送器
- OPENGL中GLU和GLUT工具箱收藏
- 利用.NET提供的Microsoft.Office.Interop.Word插件来填充资料给WORD模板
- 2012蓝桥杯省赛第十题 取球游戏 (SG打表)
- Ubuntu下初试Oracle
- Java的一些概念和例子
- 短信发送器
- Jquery 基础
- 第3章 栈和队列——栈的应用:数制转换
- 蓝桥杯(购物券)
- linux下init等级
- Ubuntu 12.04下关闭图形界面
- 程序员的出路之一
- VC窗体最小化 最大化控制
- 基于jQuery的下拉菜单菜单【02】,诸位上眼!!!