Advertisement
code_hacker

Untitled

Oct 29th, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1.     @Override
  2.     public void onReceive(Context context, Intent intent) {
  3.         // TODO Auto-generated method stub
  4.        
  5.         Intent m=new Intent(context, ReceivelocationActivity.class);    
  6.           PendingIntent pi=PendingIntent.getBroadcast(context, 0, m, 0);
  7.         Bundle bundle = intent.getExtras();        
  8.         SmsMessage[] msgs = null;
  9.         String str = "";
  10.         String str2="";
  11.         String str3="";
  12.         String autoReplyToken = "Request_Accepted";
  13.         if (bundle != null)
  14.         {
  15.             //---retrieve the SMS message received---
  16.             Object[] pdus = (Object[]) bundle.get("pdus");
  17.             msgs = new SmsMessage[pdus.length];            
  18.             for (int i=0; i<msgs.length; i++){
  19.                 msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                
  20.                 str += "SMS from " + msgs[i].getOriginatingAddress();                    
  21.                 str2=msgs[i].getOriginatingAddress();
  22.                 str += " :";
  23.                 str += msgs[i].getMessageBody().toString();
  24.              str3=msgs[i].getMessageBody().toString();
  25.                 str += "\n";        
  26.             }
  27.             //---display the new SMS message---
  28.             Toast.makeText(context, str, Toast.LENGTH_SHORT).show();
  29.           //  int number=Integer.parseInt(str2);
  30.            
  31.            
  32.        
  33.             SmsManager sms = SmsManager.getDefault();
  34.             boolean isAutoReply = str3.startsWith(autoReplyToken);
  35.  
  36.            
  37.             locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
  38.            
  39.        //     geocoder = new Geocoder(this);
  40.            
  41.           //  Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
  42.            
  43.          LocationListener listener = new LocationListener(){
  44.  
  45.            
  46.             @Override
  47.             public void onLocationChanged(Location location) {
  48.             // TODO Auto-generated method stub
  49.  
  50.  
  51.               lat=location.getLatitude();
  52.                lon=location.getLongitude();
  53.  
  54.  
  55.             }  
  56.  
  57.  
  58.             @Override
  59.             public void onProviderDisabled(String provider) {
  60.                 // TODO Auto-generated method stub
  61.                
  62.             }
  63.  
  64.             @Override
  65.             public void onProviderEnabled(String provider) {
  66.                 // TODO Auto-generated method stub
  67.                
  68.             }
  69.  
  70.             @Override
  71.             public void onStatusChanged(String provider, int status, Bundle extras) {
  72.                 // TODO Auto-generated method stub
  73.                
  74.             }
  75.            
  76.              };
  77.            
  78.         locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 10, listener);
  79.            /* if (location != null) {
  80.               Log.d(TAG, location.toString());
  81.                this.onLocationChanged(location);
  82.            
  83.               }
  84.            
  85.             lat = location.getLatitude();
  86.             lon = location.getLongitude();*/
  87.  
  88.             String msg = Double.toString(lat) + " " +Double.toString(lon) ;
  89.             if (!isAutoReply) {
  90.                 String autoReplyText = autoReplyToken + msg;
  91.                 sms.sendTextMessage(str2, null, autoReplyText, pi, null);
  92.             }
  93.  
  94.          
  95.          //   sms.sendTextMessage(str2, null, "Whats up", pi, null);
  96.  
  97.         }                
  98.     }
  99.    
  100.  
  101.    
  102.    
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement