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.Buil开发者_Go百科der(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
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.
精彩评论