1
我正在尋找一個應用程序來檢查設備的速度(如果駕駛等),並且如果它在預設的閾值下,它會通過用標準通知將SMS發送到標準接收設備。如果標準失敗(移動得太快)。我希望它仍然可以通過短信,抑制通知,並自動向發件人發送回覆。如何根據條件將SMS傳遞到默認的SMS應用程序
目前,這是我剛纔接收和發送:
package biz.midl.drivereply;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.telephony.SmsMessage;
public class MainActivity extends BroadcastReceiver {
int MAX_SPEED = 1000; //will have a change method later
@Override
public void onReceive(Context arg0, Intent arg1) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); //context cannot be resolved
Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lastKnownLocation.getSpeed() > MAX_SPEED)
{
Bundle extras = intent.getExtras(); //intent cannot be resolved
if (extras == null)
{
return;
}
abortBroadcast();
Object[] pdus = (Object[]) extras.get("pdus");
SmsMessage msg = SmsMessage.createFromPdu((byte[]) pdus[0]);
String origNumber = msg.getOriginatingAddress();
String reply = "The user is busy. Try again later.";
SmsManager.getDefault().sendTextMessage(origNumber, null, reply, null, null);
}
}
}
我與評論行之後顯示的錯誤。