I’m trying to build a program that reads SMS from a specific sender. It then parses the text into an address. A popup comes up automatically with the address and two buttons, OK (cancels the popup) and Map (send the address to a MapView showing the address). I don’t know how to create a popup that shows the time, address, and calltype.
package bkgdService;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;
public class SMSReceiver extends BroadcastReceiver
{
public int calltypeIndexA;
private String time;
private String callType;
private String location;
public void onReceive(Context context, Intent intent)
{
Bundle myBundle = intent.getExtras();
SmsMessage [] messages = null;
if (myBundle != null)
{
Object [] pdus = (Object[]) myBundle.get("pdus");
messages = new SmsMessage[pdus.length];
for (int i = 0; i < messages.length; i++)
{
if (messages[i].getOriginatingAddress() == "messaging@iamresponding.com")
{
messages[i] = SmsMessage.createFromPdu((byte[]) pdus[i]);
String message = messages[i].getMessageBody();
this.time = SupportMethods.findTime(message);
this.callType = SupportMethods.findCallType(message);
}
}
//ADD POPUP
}
}
}
Yes, many of them can be quite confusing. I will see if I can help. If your app isn’t going to be very robust, you can make the alert right there. If you think it will get much bigger, I would suggest creating a separate class for your alerts/popups and pass the data through intents link Here is a link in the docs that explains real well how to create a custom alert link. You can use this to create a custom alert to pop-up. You can either declare your message, date, etc., variables at the beginning of your application where you have your others then use them in your alert as TextViews to display in the alert. Or as I said, you may want to consider creating a separate class for them if you will have more alerts throughout your program. Hope this helps!