Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. LocationManager locationManager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
  2.  
  3. public class SMSReceiver extends BroadcastReceiver {
  4.  
  5. private String message;
  6.  
  7.  
  8. @Override
  9. public void onReceive(Context context, Intent intent) {
  10. Bundle bundle = intent.getExtras();
  11.  
  12. SmsMessage[] msgs = null;
  13. if (bundle != null) {
  14. Object[] pdus = (Object[]) bundle.get("pdus");
  15. msgs = new SmsMessage[pdus.length];
  16. if (msgs.length >= 0) {
  17. msgs[0] = SmsMessage.createFromPdu((byte[]) pdus[0]);
  18. message = msgs[0].getMessageBody().toString();
  19.  
  20.  
  21. //if it's the locating command
  22. if(message.equals("find location xyz"))
  23. {
  24. PhoneLocater pl = new PhoneLocater();
  25. pl.locatePhone();
  26. }
  27.  
  28.  
  29. else
  30. {Toast.makeText(context,"Nothing",Toast.LENGTH_LONG ).show();
  31. }
  32.  
  33.  
  34. }
  35. }
  36. }
  37. }
  38.  
  39. <receiver android:name="com.example.find_me.SMSReceiver">
  40. <intent-filter>
  41. <action android:name="android.provider.Telephony.SMS_RECEIVED" />
  42. </intent-filter>
  43.  
  44. @Override
  45. public void onReceive(Context context, Intent intent) {
  46. LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
  47. // whatever you need to do
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement