Mr.James
Mr.James

Reputation: 386

How to show dialog during the Receiver?

I want to show the dialog during the Receiver , i used this code but it's not true, can anyone help me?

public class Call_Sevice extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String number = intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER);
if (TelephonyManager.EXTRA_STATE_RINGING.equals(state)){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Message");
builder.setMessage("Its Ringing [" + number + "]");
builder.setNeutralButton("Confrim", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id){
System.exit(0);
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
}

Thanks

Upvotes: 0

Views: 429

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006819

You cannot "show the dialog during the Receiver". You can create an Activity that is themed to look like a dialog (Theme.Dialog) and start that activity.

Upvotes: 3

Related Questions