Android入门之简单短信发送器
效果图:
manifest.xml 文件中加入 <uses-permission android:name="android.permission.SEND_SMS"/>
<?xml version="1.0" encoding="utf-8"?>
<resources> <string name="app_name">sms</string>
<string name="action_settings">Settings</string>
<string name="number">请输入手机号</string>
<string name="content">请输入文本</string>
<string name="button">发送</string>
<string name="success">短信发送成功!</string>
</resources>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
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/number" /> <EditText
android:id="@+id/numberText"
android:layout_width="match_parent"
android:layout_height="wrap_content" /> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/content" /> <EditText
android:id="@+id/contentText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="3" /> <Button
android:id="@+id/Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button" /> </LinearLayout>
package jk.sms; import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends Activity { private EditText NumberText;
private EditText ContentText; protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
NumberText = (EditText) this.findViewById(R.id.numberText);
ContentText = (EditText) this.findViewById(R.id.contentText);
Button button = (Button) this.findViewById(R.id.Button);
button.setOnClickListener(new ButtonClickListener());
}
@SuppressLint("ShowToast")
private final class ButtonClickListener implements OnClickListener { public void onClick(View v) {
String number = NumberText.getText().toString();
String content = ContentText.getText().toString();
SmsManager manager = SmsManager.getDefault();
ArrayList<String> texts = manager.divideMessage(content); //超过规定长度后短信拆分
for (int i = 0; i < texts.size(); i++) {
manager.sendTextMessage(number, null, content, null, null);
}
Toast.makeText(MainActivity.this, R.string.success,
Toast.LENGTH_LONG);
}
} 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;
} }
Android入门之简单短信发送器的更多相关文章
- Android实现简单短信发送器
布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...
- Android简易实战教程--第四话《最简单的短信发送器》
首先配置一个布局: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmln ...
- Android实战--短信发送器
首先设计界面 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:t ...
- 无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)
1.Android是什么 手机设备的软件栈,包括一个完整的操作系统.中间件.关键的应用程序,底层是linux内核,安全管理.内存管理.进程管理.电源管理.硬件驱动 2.Dalvik VM 和 JVM ...
- android开发学习---开发一个简易的短信发送器
一.需求: 开发一个简易的短信发送器,输入:对方手机号码,短信内容,点击发送按钮,短信发送成功,对方手机成功收到短信. 其中要求短信内容过长时可以自动拆分,长度英文是160个英文,中文是70个,中英混 ...
- Android短信发送器_08
1.string xml代码 <?xml version="1.0" encoding="utf-8"?> <resources> &l ...
- 初识安卓小程序(Android短信发送器)
首先,先创建一个安卓项目(我的版本号是4.4.2的),名字为"短信发送器" 然后在res目录下找到layout目录,找到activity_main.xml或fragment_mai ...
- Android短信发送器(2)
在上一篇的<Android短信发送器>当中.发送功能并不完好.当发送内容超过限定字数时,短信就会发送失败,此时就须要推断内容是否超过限制,假设不超过限制.就直接发送,反之.则对其进行处理再 ...
- 向android模拟器打电话发短信的简单方法
在开发android应用程序时,有时候需要测试一下向android手机拨打电话发送短信时该应用程序的反应.譬如编写一个广播接收器,来提示用户有短信收到或者处理短信,就需要向该手机发送短信来进行测试.这 ...
随机推荐
- HTML+CSS - 搜索 And 高级搜索
- Swift - 给表格UITableView添加索引功能(快速定位)
像iOS中的通讯录,通过点击联系人表格右侧的字母索引,我们可以快速定位到以该字母为首字母的联系人分组. 要实现索引,我们只需要两步操作: (1)实现索引数据源代理方法 (2)响应点击索引触发的代理 ...
- ALV前导零的问题
ALV的IT_FIELDCAT参数中L_ZERO 选项置位的话,对NUM类型的前导0是可以输出的,但是有个很重要的前提条件,NO_ZERO不可以置位,否则L_ZERO是失效的.
- VS2010(2012)中使用Unit Testing进行单元测试
原文 VS2010(2012)中使用Unit Testing进行单元测试 使用VS 2012自带的Unit Testing工具进行单元测试是非常方便的.网上关于这方面的例子很多,这篇随笔只起个人学习笔 ...
- 使用perf生成Flame Graph(火焰图)
具体的步骤参见这里: <flame graph:图形化perf call stack数据的小工具> 使用SystemTap脚本制作火焰图,内存较少时,分配存储采样的数组可能失败,需 ...
- Call Transaction 小节
采购订单: . CALL FUNCTION ‘ME_DISPLAY_PURCHASE_DOCUMENT’ EXPORTING i_ebeln = itab-ebeln EXCEPTIONS not_f ...
- uva 10196 Check The Check
题目:10196 - Check The Check 思路:水题..模拟 这个代码,前半部分是在数统机房上课的时候写的,挫了点,懒得改了. #include <cstdio> #inclu ...
- 浅谈mapreduce程序部署
尽管我们在虚拟机client上能非常快通过shell命令,进行运行一些已经封装好实例程序,可是在应用中还是是自己敲代码,然后部署到server中去,以下,我通过程序进行浅谈一个程序的部署过程. 在启动 ...
- Android改变系统自带环形ProgressBar的大小
MainActivity如下: package cc.testprogressbar; import android.os.Bundle; import android.app.Activity; / ...
- linux—select具体解释
linux—select具体解释 select系统调用时用来让我们的程序监视多个文件句柄的状态变化的.程序会停在select这里等待,直到被监视的文件句柄有一个或多个发生了状态改变. 关于文件句柄,事 ...