我开发了一个应用程序,我将一个sms代码从friendmobile发送到lostmobile。如果代码匹配,那么lostmobile的位置应该发送到friendmobile。步骤是
这是我的代码:
public void onLocationChanged(Location location) {
Toast.makeText(this,"inside onlocationchanged", Toast.LENGTH_LONG).show();
if(location!=null) {
Double latitude = location.getLatitude();
Double longitude = location.getLongitude();
Toast.makeText(this, "latitude1" + latitude + "longitude1" + longitude, Toast.LENGTH_LONG).show();
Intent i=new Intent(this,Locationsms.class);
i.putExtra("latitude",latitude);
sendBroadcast(i);
Toast.makeText(this,"afterbroadcast", Toast.LENGTH_LONG).show();
}
}
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "onstartcommand", Toast.LENGTH_LONG).show();
BroadcastReceiver smsReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context,"inside service broadcastreceiver", Toast.LENGTH_LONG).show();
Bundle b = intent.getExtras();
String number = b.getString("number");
String message = b.getString("messagebody");
String s=intent.getStringExtra("latitude");
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, message + "lat" + s, null, null);
Toast.makeText(context,"smssent", Toast.LENGTH_LONG).show();
}
};
IntentFilter filter = new IntentFilter(Intent.ACTION_SEND);
registerReceiver(smsReceiver, filter);
}
但我的问题是这个接收器从未被调用过 如何将短信发回给发件人,其中包含纬度和经度,这有助于我发挥作用
public class Locationsms extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "inside receive1.", Toast.LENGTH_LONG).show();
}
}
这个吐司正在执行但是短信无法发回