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. Java按位置解析文本文件(使用Swing选择文件)

    工作中遇到这样的一个需求,按位置解析一些文本文件,它们由头部.详情.尾部组成,并且每一行的长度可能不一样,每一行代表的意思也可能不一样,但是每一行各个位置代表的含义已经确定了. 例如有下面这样一段文本 ...

  2. oracle database resident connection pooling(驻留连接池)

    oracle在11g中引入了database resident connection pooling(DRCP).在此之前,我们可以使用dedicated 或者share 方式来链接数据库,dedic ...

  3. lunux下查看文件文件夹大小的命令

    使用ls -lht命令显示当前目录下的所有文件,其中有一列就是显示这个文件的大小.如果要看一个文件夹的大小,可以用du -sh *

  4. Android 常用UI控件之TabHost(1)TabHost的两种布局方式

    TabHost是Android中的tab组件. TabHost布局文件的基本结构 TabHost下有个layout,这个layout中有TabWidget与FrameLayout.TabWidget是 ...

  5. 【HDOJ】2155 小黑的镇魂曲

    线段树+SPFA最短路可以过.或者DP也能过.需要注意的是xl的范围是错的,测试用例中xl可能为0,他妈的,因为这个一直莫名其妙的wa.1. spfa建图增加一倍的点即可(讨论左端点和右端点). /* ...

  6. Binary to Text (ASCII) Conversion

    Binary to Text (ASCII) Conversion Description: Write a function that takes in a binary string and re ...

  7. MFC VS2005 添加Override 和 Message

    VS2005 1.Overrides OnInitDialog() 在Class View选中 这个类,然后properties中点Message 旁边的Overrides, 添加OnInitDial ...

  8. Problems encountered while deleting resources.

    Error The project was not built due to “Problems encountered while deleting resources.”. Fix the pro ...

  9. WPF学习小记

    WPF通用控制事件 Click:当控件被单击时发生.某些情况下,当用户按下Enter键时也会发生这样的事件. Drop:当拖曳操作完成时发生,也就是说,当用户将某个对象拖曳dao该控件上,然后松开鼠标 ...

  10. [转]用C#实现的条形码和二维码编码解码器

    条形码的标准: 条形码的标准有ENA条形码.UPC条形码.二五条形码.交叉二五条形码.库德巴条形码.三九条形码和128条形码等,而商品上最常使用的就是EAN商品条形码.EAN商品条形码亦称通用商品条形 ...