我在github上找到了一个关于位置跟踪器的项目。我想改变它。 它是如何工作的? 您在设备中安装此应用程序。 从另一台设备发送消息到您的设备(您的消息必须在哪里?)(您之前安装应用程序的设备)。当您发送此消息时,1分钟后您会收到一个显示当前位置的链接。 https://github.com/quentin7b/android-location-tracker(link项目) 现在我想发送任何消息。不限发送到哪儿了? 现在我想从用户获取字符串保存然后比较然后如果有相同的发送位置链接。 在这个活动中,我必须得到字符串来保存。 这是代码:
public class LocationTrackerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
在这里:
public class SMSReceiver extends BroadcastReceiver
{
LocationManager lm;
LocationListener locationListener;
String senderTel;
@Override
public void onReceive(Context context, Intent intent)
{
//---get the SMS message that was received---
Bundle bundle = intent.getExtras();
SmsMessage[] msgs = null;
String str="";
if (bundle != null)
{
senderTel = "";
//---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]);
if (i==0) {
//---get the sender address/phone number---
senderTel = msgs[i].getOriginatingAddress();
}
//---get the message body---
str += msgs[i].getMessageBody().toString();
}
if (str.startsWith("Where are you?")) {
//---use the LocationManager class to obtain locations data---
lm = (LocationManager)
context.getSystemService(Context.LOCATION_SERVICE);
//---request location updates---
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
60000,
1000,
locationListener);
//---abort the broadcast; SMS messages won’t be broadcasted---
this.abortBroadcast();
}
}
}
private class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc) {
if (loc != null) {
//---send a SMS containing the current location---
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(senderTel, null,
"http://maps.google.com/maps?q=" + loc.getLatitude() + "," +
loc.getLongitude(), null, null);
//---stop listening for location changes---
lm.removeUpdates(locationListener);
}
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
}
}
在这段代码中它与你在哪里比较?
if (str.startsWith("Where are you?")) {
//---use the LocationManager class to obtain locations data---
lm = (LocationManager)
context.getSystemService(Context.LOCATION_SERVICE);
//---request location updates---
locationListener = new MyLocationListener();
lm.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
60000,
1000,
locationListener);
重点是我是android新手。我没有哪个关键词帮助我搜索我的问题可以帮助我。 请帮忙 提前谢谢