Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onReceive(Context context, Intent intent) {
- // TODO Auto-generated method stub
- Intent m=new Intent(context, ReceivelocationActivity.class);
- PendingIntent pi=PendingIntent.getBroadcast(context, 0, m, 0);
- Bundle bundle = intent.getExtras();
- SmsMessage[] msgs = null;
- String str = "";
- String str2="";
- String str3="";
- String autoReplyToken = "Request_Accepted";
- if (bundle != null)
- {
- //---retrieve the SMS message received---
- Object[] pdus = (Object[]) bundle.get("pdus");
- msgs = new SmsMessage[pdus.length];
- for (int i=0; i<msgs.length; i++){
- msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);
- str += "SMS from " + msgs[i].getOriginatingAddress();
- str2=msgs[i].getOriginatingAddress();
- str += " :";
- str += msgs[i].getMessageBody().toString();
- str3=msgs[i].getMessageBody().toString();
- str += "\n";
- }
- //---display the new SMS message---
- Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
- // int number=Integer.parseInt(str2);
- SmsManager sms = SmsManager.getDefault();
- boolean isAutoReply = str3.startsWith(autoReplyToken);
- locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
- // geocoder = new Geocoder(this);
- // Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- LocationListener listener = new LocationListener(){
- @Override
- public void onLocationChanged(Location location) {
- // TODO Auto-generated method stub
- lat=location.getLatitude();
- lon=location.getLongitude();
- }
- @Override
- public void onProviderDisabled(String provider) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onProviderEnabled(String provider) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- // TODO Auto-generated method stub
- }
- };
- locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);
- /* if (location != null) {
- Log.d(TAG, location.toString());
- this.onLocationChanged(location);
- }
- lat = location.getLatitude();
- lon = location.getLongitude();*/
- String msg = Double.toString(lat) + " " +Double.toString(lon) ;
- if (!isAutoReply) {
- String autoReplyText = autoReplyToken + msg;
- sms.sendTextMessage(str2, null, autoReplyText, pi, null);
- }
- // sms.sendTextMessage(str2, null, "Whats up", pi, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement