Android实现短信发送器
来源:互联网 发布:虚拟ip地址软件 编辑:程序博客网 时间:2024/05/20 02:29
短信发送器
短信发送器和电话拨号器步骤差不多,需要注意的是当获取到短信内容时,如果短信内容非常多需要对短信内容进行拆分,拆分后存到集合里,对短信内容多条发送
效果图:
界面布局:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- >
- <!--显示控件-->
- <TextView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:text="@string/moblie"
- />
- <!--文本框按钮-->
- <EditText
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- android:id="@+id/moblie"
- />
- <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/content"
- />
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/button"
- android:id="@+id/button"
- />
- </LinearLayout>
Activity:
- package cn.test.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 {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Button button =(Button)this.findViewById(R.id.button);
- button.setOnClickListener(new ButtonClickLister()); //点击事件的处理对象
- }
- //监听对象实现拨打功能
- private class ButtonClickLister implements View.OnClickListener{
- public void onClick(View v){
- EditText moblieText=(EditText)findViewById(R.id.moblie);
- EditText contentText=(EditText)findViewById(R.id.content);
- String moble =moblieText.getText().toString();//获取电话号
- String content =contentText.getText().toString();//获取短信内容
- SmsManager smsManager=SmsManager.getDefault();//获得短信管理器
- ArrayList<String> texts=smsManager.divideMessage(content);//对短信内容进行拆分
- for(String text:texts){
- smsManager.sendTextMessage(moble, null, text, null, null); //短信发送
- }
- //采用吐西方式提示用户发送成功
- Toast.makeText(getApplicationContext(), R.string.success, 1).show();
- }
- }
- }
添加短信服务权限:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="cn.itcast.action"
- android:versionCode="1"
- android:versionName="1.0">
- 略....
- <uses-sdk android:minSdkVersion="8" />
- <!-- 短信服务权限 -->
- <uses-permission android:name="android.permission.SEND_SMS" />
- </manifest>
0 0
- Android实现短信发送器
- Android实现发送短信
- Android实现发送短信
- Android 短信发送器的实现
- Android 短信发送器的实现
- Android短信发送器的实现
- android-短信发送器的实现
- Android----实现短信发送器功能
- Android短信发送器
- android 短信发送器
- android短信发送器
- Android短信发送器
- android短信发送器
- android 短信发送器
- Android短信发送器
- Android -- 短信发送器
- android 短信发送器
- Android短信发送器
- 高新技术(反射、内省、类加载器、代理)
- JS--01
- 管理vc工程目录
- COM学习笔记(二):引用计数
- JS RSA 签名实现
- Android实现短信发送器
- overload与override的区别
- ext3文件系统基础
- float你真的懂了吗
- 极光推送使用 IOS端
- 了解android的基本知识
- 编程珠玑第一章位图排序扩展算法(可以排列包含负数的整数)
- android 中调用接口发送短信
- CrtmpServer支持Android与IOS进行RTMP直播遇到的_checkbw问题