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. Android layout_gravity失效的问题

    相信对于Android的初学者来说,大家都曾经被layout里这两个极其相似的属性迷惑过.简单使用一下搜索工具,我们就不难找到下面这样的答案: layout_gravity 表示组件自身在父组件中的位 ...

  2. HashMap与HashTable联系与区别

    HashMap与HashTable 1.hashMap去掉了HashTable 的contains方法,但是加上了containsValue()和containsKey()方法. 2.hashTabl ...

  3. php陷阱:字符串和数字比较

    PHP中的比较运算符有点诡异,很容易出错,现列出比较规则: 1.当两个字符进行大小比较时,是比较着这两个字符的ASCII码大小——这条很容易理解. 2.当两个字符串进行大小比较时,是从第一个字符开始, ...

  4. 在Myeclipse buildpath 加server lib

    把eclipse下的工程复制过来后,发现缺少Server Runtime.本想直接在buildpath里加lib,在Myeclipse里找了一圈,恁是没发现在哪里可以添加,虽然在preference里 ...

  5. udelay、mdelay、ndelay、msleep使用比较说明

    时间单位:    毫秒(ms).微秒 (μs).纳秒(ns).皮秒(ps).飞秒(fs).阿秒.渺秒    1 s = 10^3 ms = 10^6 us = 10^9 ns = 10^12 ps = ...

  6. vijos p1193 扫雷

      描述 相信大家都玩过扫雷的游戏.那是在一个n*n的矩阵里面有一些雷,要你根据一些信息找出雷来.万圣节到了,“余”任过流行起了一种简单的扫雷游戏,这个游戏规则和扫雷一样,如果某个格子没有雷,那么它里 ...

  7. JS中的substring和substr函数的区别

    1. 在JS中, 函数声明: stringObject.substring(start,stop) start是在原字符串检索的开始位置,stop是检索的终止位置,返回结果中不包括stop所指字符. ...

  8. Android获取IMSI和IMEI

    IMSI是一个 唯一的数字, 标识了GSM和UMTS 网络里的唯一一个用户. 它 存储 在手机的SIM卡里,它会通过手机发送到网络上. IMEI也是一串唯一的数字, 标识了 GSM 和 UMTS网络里 ...

  9. fcitx中文输入法

    Ubuntu自带的输入法不太尽如人意思,用起来也不方便,我在Ubuntu和FC中都是用Fcitx,很好用! 安装配置如下: 1. 安装 fcitx sudo apt-get install fcitx ...

  10. Velocity资源

    这里有非常多的资源和示例提供给程序员,我们推荐您查阅我们提供的示例.文档和源代码.下面是一些非常有用的资源列表: 用户和开发者社区:可以通过mail-lists加入我们.mail-lists网页地址: ...