SmsManager可以在后台发送短信,无需用户操作,开发者就用这个SmsManager功能在后台偷偷给SP发短信,导致用户话费被扣。必须添加android.permission.SEND_SMS权限。

<uses-permission android:name="android.permission.SEND_SMS" />

如果短信内容过长,可以使用SmsManager.divideMessage(String text)方法自动拆分成一个ArrayList数组,再根据数组长度循环发送。

用sendMultipartTextMessage(String destinationAddress, string scAddress, ArrayList<String> parts, ArrayList<PendingIntent> sentIntents, ArrayList<PendingIntent> deliveryIntents)方法发送。

参数分别为号码,短信服务中心号码(null 即可),短信内容,短信发送结果广播PendingIntent,短信到达广播。

下面写一个demo查移动话费余额,贴上代码:

package com.dimos.sendmessage;

import java.util.ArrayList;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.telephony.SmsManager; public class SendMessageActivity extends Activity { @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); SendReceiver receiver=new SendReceiver();
IntentFilter filter=new IntentFilter();
filter.addAction(SendReceiver.ACTION);
registerReceiver(receiver,filter);
//必须先注册广播接收器,否则接收不到发送结果 SmsManager smsManager = SmsManager.getDefault();
Intent intent = new Intent();
intent.setAction(SendReceiver.ACTION);
ArrayList<String> divideMessage = smsManager.divideMessage("ye");
PendingIntent sentIntent = PendingIntent.getBroadcast(this, 1, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
ArrayList<PendingIntent> sentIntents = new ArrayList<PendingIntent>();
sentIntents.add(sentIntent); try {
smsManager.sendMultipartTextMessage("10086", null,
divideMessage, sentIntents, null);
} catch (Exception e) {
e.printStackTrace();
}
}
}

接收器:

package com.dimos.sendmessage;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; public class SendReceiver extends BroadcastReceiver { public static final String ACTION = "action.send.sms"; @Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (ACTION.equals(action)) {
int resultCode = getResultCode();
if (resultCode == Activity.RESULT_OK) {
// 发送成功
System.out.println("发送成功!");
} else {
// 发送失败
System.out.println("发送失败!");
}
}
} }

Android SmsManager 发送短信的更多相关文章

  1. android之发送短信程序

    首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...

  2. Android 学习第13课,android 实现发送短信的功能

    1. 界面布局 界面代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

  3. Android之发送短信和接收验证码

      最近项目需求需要发送短信和接收验证码并将验证码显示在输入框中 以下是我的记录    前提---权限     <uses-permission android:name="andro ...

  4. Android之发送短信的两种方式

    SMS涉及的主要类SmsManager 实现SMS主要用到SmsManager类,该类继承自java.lang.Object类,下面我们介绍一下该类的主要成员. 公有方法: ArrayList< ...

  5. (转)Android之发送短信的两种方式

    https://www.cnblogs.com/dongweiq/p/4866022.html if(TextUtils.isEmpty(number)||TextUtils.isEmpty(cont ...

  6. Android 中发送短信

    import android.net.Uri; //调用Android系统API发送短信 Uri uri = Uri.parse("smsto:" + strSmsPhone_va ...

  7. android 60 发送短信

    import android.os.Bundle; import android.app.Activity; import android.telephony.SmsManager; import a ...

  8. 至Android虚拟机发送短信和拨打电话

    Android的emulator是已经包括了gsm 模块,能够模拟电话与短信进行调试(就不用花太多冤枉钱) 首先,肯定是打开虚拟机: emulator -avd XXXXXX -scale 0.8&a ...

  9. java攻城师之路(Android篇)--搭建开发环境、拨打电话、发送短信、布局例子

    一.搭建开发环境 1.所需资源 JDK6以上 Eclipse3.6以上 SDK17, 2.3.3 ADT17 2.安装注意事项 不要使用中文路径 如果模拟器默认路径包含中文, 可以设置android_ ...

随机推荐

  1. hbase安装(zookeeper等)

    文库:http://wenku.baidu.com/link?url=5mnYL7ZuxUBWZnrnmak4JRVF5fJquJmjgmZy788i7UW8lUk4QXD8Nc_haPz33vjt9 ...

  2. Form.KeyPreview 属性

    Form.KeyPreview 属性 今天再做KeyDown 和 KeyUp 事件时,就是忘了设置,窗体的KeyPreview 属性,所以KeyDown 和 KeyUp 事件没有反应(这里说明一下,本 ...

  3. WIP_DISCRETE_JOBS.STATUS_TYPE

    WIP_DISCRETE_JOBS.STATUS_TYPE Value Meaning 7 Cancelled 8 Pending Bill Load 9 Failed Bill Load 10 Pe ...

  4. WPF——传实体类

    User u; private void Button_Click_1(object sender, RoutedEventArgs e) //点击登陆按钮,弹出新窗体 { //先判断一下是不是正确的 ...

  5. NOI 2014 感想

    NOI2014结束了,我卡线登上了领奖台... 这是我第一次NOI,我觉得我收获了很多东西: 1.考前心态不重要,重要的是实力 真正考试的时候是顾不得想其他事情的 2.测试数据是人出的!不是随机的!不 ...

  6. 五个你可能闻所未闻的出色的Ubuntu替代发行版

      你在使用Ubuntu,可是希望桌面体验……来得更眩目一点.虽说你总是可以添加新的桌面背景,或者索性切换桌面,但是你还有这个选择:换成一种全然不同的发行版. 本文就介绍了五个极其出色的Ubuntu替 ...

  7. cmd for 用法

    1:for命令及变量 基本格式: FOR /参数 %variable IN (set) DO command [command_parameters] %variable:指定一个单一字母可替换的参数 ...

  8. Mac OS X 10.10(yosemite)更新后,cocoapods出错, 及cocoapods更新至0.34后, 错误情况整理

    1:Mac升级10.10后,执行pod install出错如下 QTX-Will-mini:NewHishop willbin$ pod install [!] Unable to load a sp ...

  9. SharePoint Services 数据库表

    转:http://dugan.bokee.com/630446.html 以下是Microsoft Windows SharePoint Services架构中数据库列表. Configuration ...

  10. FastCGI技术

    1         FastCGI介绍 FastCGI:快速通用网关接口(Fast Common Gateway Interface/FastCGI)是一种让交互程序与Web服务器通信的协议.    ...