当我的汽车行驶速度超过90公里/小时时,我正试图从我的应用程序发送短信。对于检测速度,我使用location.hasSpeed()。但是,每当应用程序到达Sms代码时停止运行。 它应该在计数器达到10时发送短信。
@Override
public void onLocationChanged(Location location) {
if (location != null) {
curlat = location.getLatitude();
curlong = location.getLongitude();
Location locationA = new Location("point A");
locationA.setLatitude(startlat);
locationA.setLongitude(startlong);
Location locationB = new Location("point B");
locationB.setLatitude(curlat);
locationB.setLongitude(curlong);
double distance = locationA.distanceTo(locationB);
if (distance > 5) {
res = (res + distance);
dreading.setText(String.format("%.2f", (res/1000) ));
startlong = curlong;
startlat = curlat;
}
if (location.hasSpeed()) {
//mySpeed = location.getSpeed()*1.852;
mySpeed = location.getSpeed() * 3.6;
sreading.setText(String.format("%.2f", mySpeed));
if (mySpeed > 70) {
warning.setText("Warning!");
}else{
warning.setText("Normal");
}
if (mySpeed > 2) {
counter++;
}
if(counter>10)//error comes here!
{
Toast.makeText(getApplicationContext(), "Alert Sent",
Toast.LENGTH_LONG).show();
String messageToSend = "Rash driving detected.\nOwner Name:"+temp+"\nDriver Name:"+temp1+"\nVehicle Number:"+temp2+ "\nLatitude:" + curlat + "\nLongitude:" + curlong + "\nCheck here:\nhttps://maps.google.com/maps?q=" + curlat + "," + curlong;
smsMan.sendTextMessage(temp3, null, messageToSend, null, null);
smsMan1.sendTextMessage(temp4, null, messageToSend, null, null);
counter=0;
}
}
}
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@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
}
}