Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LocationManager locationManager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
- public class SMSReceiver extends BroadcastReceiver {
- private String message;
- @Override
- public void onReceive(Context context, Intent intent) {
- Bundle bundle = intent.getExtras();
- SmsMessage[] msgs = null;
- if (bundle != null) {
- Object[] pdus = (Object[]) bundle.get("pdus");
- msgs = new SmsMessage[pdus.length];
- if (msgs.length >= 0) {
- msgs[0] = SmsMessage.createFromPdu((byte[]) pdus[0]);
- message = msgs[0].getMessageBody().toString();
- //if it's the locating command
- if(message.equals("find location xyz"))
- {
- PhoneLocater pl = new PhoneLocater();
- pl.locatePhone();
- }
- else
- {Toast.makeText(context,"Nothing",Toast.LENGTH_LONG ).show();
- }
- }
- }
- }
- }
- <receiver android:name="com.example.find_me.SMSReceiver">
- <intent-filter>
- <action android:name="android.provider.Telephony.SMS_RECEIVED" />
- </intent-filter>
- @Override
- public void onReceive(Context context, Intent intent) {
- LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
- // whatever you need to do
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement