The title is not as specific as I would like, so here are more details. I am trying to make an app that auto-replies a message to any incoming texts while driving. This app is 100% working thanks to this community already, but I would like to expand this. My goal is to get the number of the sender (I already have this) but then save it separately somehow so that it does auto-reply to the same person twice (or more) in a row.
public class Receiver extends BroadcastReceiver {
public static String number = "";
public static String sms = "";
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
SmsMessage[] msgs;
if (bundle != null) {
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]);
number = msgs[i].getOriginatingAddress();
sms = msgs[i].getMessageBody();
}
if (Main.serviceBroadcast) {
String sent = "SMS_SENT";
PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(sent), 0);
SmsManager sm = SmsManager.getDefault();
if (Main.serviceReply && !number.equals("")) {
sm.sendTextMessage(number, null, Main.reply, pi, null);
Toast.makeText(context, "replied to " + number, Toast.LENGTH_SHORT).show();
}
}
}
}
}
If you would like the full source to this program please visit http://mellowdev.net