如何在接收器期间显示对话框?

时间:2011-07-07 15:36:50

标签: android

我想在Receiver期间显示对话框,我使用了这段代码,但事实并非如此,有人可以帮助我吗?

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();
}
}
}

由于

1 个答案:

答案 0 :(得分:3)

您无法“在接收器期间显示对话框”。您可以创建一个主题为Activity的对话框(Theme.Dialog)并启动该活动。