-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainActivity.java
More file actions
executable file
·71 lines (57 loc) · 2.43 KB
/
MainActivity.java
File metadata and controls
executable file
·71 lines (57 loc) · 2.43 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
package net.learn2develop.detectoutgoingsms;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.ContentObserver;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
public class MainActivity extends Activity {
ContentResolver contentResolver;
ContentObserver smsContentObserver;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contentResolver = getContentResolver();
}
@Override
public void onResume() {
super.onResume();
smsContentObserver = new ContentObserver(new Handler()) {
@Override
public void onChange(boolean selfChange) {
Uri smsURI = Uri.parse("content://sms/sent");
Cursor c = getContentResolver().query(smsURI,
new String[] { "address", "date", "body", "type" },
null, null, null);
String[] columns = new String[] {
"address", "date", "body","type" };
//---go to the first row; which is the most recently
// sent message---
c.moveToNext();
//---get the various properties of the SMS message---
String recipient = c.getString(c.getColumnIndex(columns[0]));
String date = c.getString(c.getColumnIndex(columns[1]));
String message = c.getString(c.getColumnIndex(columns[2]));
String type = c.getString(c.getColumnIndex(columns[3]));
//---print out the details of the message---
Log.d("DetectOutoingSMS", recipient + ", " + date + ", " +
message + ", " + type);
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
};
contentResolver.registerContentObserver(
Uri.parse("content://sms"), true, smsContentObserver);
}
@Override
public void onDestroy() {
super.onDestroy();
contentResolver.unregisterContentObserver(
smsContentObserver);
}
}