I'm making an app that when receiving a call gets the number of the incoming call, looks for it in a BD, and shows a message with the data associated with that number. So far, I notified it with a Toast, I want it to show something like an alert dialog but it does not work, how can I do this? ...
with this class I get the incoming call number:
public class MyCallReceiver extends BroadcastReceiver {
String incomingNumber;
@Override
public void onReceive(Context context, Intent intent) {
//verfica que esta entrando una llamada y gruada el número...
if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_RINGING)) {
incomingNumber = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
MiBaseDatos MDB = new MiBaseDatos(context);
String numero = null;
if (incomingNumber.charAt(0) == '+') {
numero = incomingNumber.substring(3);
}
if (incomingNumber.charAt(0) == '9') {
numero = incomingNumber.substring(4, 12);
}
Toast.makeText(context, "LLama de: " + MDB.recuperarPERSONA(numero).getName() + " " + incomingNumber, Toast.LENGTH_LONG).show();
// AlertDialog.Builder builder = new AlertDialog.Builder(context);
//
// builder.setTitle("LLamada Entrante de:")
// .setMessage(MDB.recuperarPERSONA(incomingNumber).getName() + " " + incomingNumber)
// .setIcon(R.mipmap.ic_launcher)
// .show();
} else if (intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_IDLE) || intent.getStringExtra(TelephonyManager.EXTRA_STATE).equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
Toast.makeText(context, "LLamada finalizada", Toast.LENGTH_LONG).show();
}
}
Here I show the message correctly with the class tosat but when I replace it with the alert dialg that this comment does not work ....