-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIncomingSms
156 lines (112 loc) · 6.23 KB
/
IncomingSms
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package com.example.lockscreen;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.telephony.SmsManager;
import android.telephony.gsm.SmsMessage;
import android.util.Log;
import android.widget.Toast;
public class IncomingSms extends BroadcastReceiver
{
// Get the object of SmsManager
LocationManager locationManager ;
String provider;
//SharedPreferences Contact_Sett_Pref ;
final SmsManager sms = SmsManager.getDefault();
public void onReceive(Context context, Intent intent)
{
SharedPreferences Contact_Sett_Pref ;
Contact_Sett_Pref = context.getSharedPreferences("Contact_Sett_Pref", Context.MODE_PRIVATE);
float own_longitude = Contact_Sett_Pref.getFloat("longitude",0f);
float own_lattitude = Contact_Sett_Pref.getFloat("lattitude",0f);
/*locationManager = (LocationManager)getSystemService(context.LOCATION_SERVICE);
// Creating an empty criteria object
Criteria criteria = new Criteria();
// Getting the name of the provider that meets the criteria
provider = locationManager.getBestProvider(criteria, false);
if(provider!=null && !provider.equals("")){
// Get the location from the given provider
Location location = locationManager.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider, 20000, 1, this);
if(location!=null)
onLocationChanged(location);
else
Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
}*/
// Retrieves a map of extended data from the intent.
final Bundle bundle = intent.getExtras();
try
{
if (bundle != null) {
final Object[] pdusObj = (Object[]) bundle.get("pdus");
for (int i = 0; i < pdusObj.length; i++) {
SmsMessage currentMessage = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
String phoneNumber = currentMessage.getDisplayOriginatingAddress();
String senderNum = phoneNumber;
String message = currentMessage.getDisplayMessageBody();
Log.i("SmsReceiver", "senderNum: "+ senderNum + "; message: " + message);
String splitted_array[] = message.split(" ");
Toast.makeText(context,splitted_array[2]+" , "+splitted_array[4],Toast.LENGTH_LONG).show();
if(splitted_array[0].equals("Emergency"))
{
Vibrator vibrator= (Vibrator)context.getSystemService(context.VIBRATOR_SERVICE);
vibrator.vibrate(5000);
//Intent intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?saddr=17.428323,78.412567&daddr=28.6454414,77.0907573"));
Intent geo_intent = new Intent(android.content.Intent.ACTION_VIEW,Uri.parse("http://maps.google.com/maps?saddr="+own_lattitude/*17.428323*/+","+own_longitude+/*78.412567*/"&daddr="+splitted_array[2]+","+splitted_array[4]/*77.0907573*/));
geo_intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
geo_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(geo_intent);
}
/*
sendReplySms(senderNum);
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Boolean tts1 = sharedPrefs.getBoolean("tts", false);
if(tts1)
tts.speak("You have a message.A reply has been sent.", TextToSpeech.QUEUE_FLUSH, null);
//sendMsgNotification(senderNum);
// Show Alert
*/ /*int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context,
"senderNum: "+ senderNum + ", message: " + message, duration);
toast.show();
*/
} // end for loop
} // bundle is null
} catch (Exception e)
{
Log.e("SmsReceiver", "Exception smsReceiver" +e);
}
}
/*@Override
public void onLocationChanged(Location location)
{
float longitude = (float) location.getLongitude();
float lattitude = (float) location.getLatitude();
//Toast.makeText(getBaseContext(), "longitude = "+longitude+"lattitude = "+lattitude, Toast.LENGTH_LONG).show();
edit_Contact_Sett_Pref.putFloat("longitude",longitude);
edit_Contact_Sett_Pref.putFloat("lattitude",lattitude);
edit_Contact_Sett_Pref.commit();
//Contact_Sett_Pref.getFloat("longitude",0f);
Toast.makeText(getBaseContext(), "longitude = "+Contact_Sett_Pref.getFloat("longitude",0f)+
"lattitude = "+Contact_Sett_Pref.getFloat("lattitude",0f), Toast.LENGTH_LONG).show();
Log.e("long", " "+Contact_Sett_Pref.getFloat("longitude", 0f));
Log.e("long", " "+Contact_Sett_Pref.getFloat("lattitude", 0f));
//return (longitude+" "+lattitude);
// Getting reference to TextView tv_longitude
TextView tvLongitude = (TextView)findViewById(R.id.tv_longitude);
// Getting reference to TextView tv_latitude
TextView tvLatitude = (TextView)findViewById(R.id.tv_latitude);
// Setting Current Longitude
tvLongitude.setText("Longitude:" + location.getLongitude());
// Setting Current Latitude
tvLatitude.setText("Latitude:" + location.getLatitude() );*/
}