Android C2DM接收时显示警报对话框
我有一个C2DM的工作实现,如果我用祝酒词来处理收到的每条消息 相反,我希望使用一个警报对话框,用户对其说“确定”,以便确认消息 我为此编写的代码在show()行生成了一个异常。我认为问题可能与所使用的上下文有关(?) 全班(根据评论中的要求):Android C2DM接收时显示警报对话框,android,android-alertdialog,android-c2dm,Android,Android Alertdialog,Android C2dm,我有一个C2DM的工作实现,如果我用祝酒词来处理收到的每条消息 相反,我希望使用一个警报对话框,用户对其说“确定”,以便确认消息 我为此编写的代码在show()行生成了一个异常。我认为问题可能与所使用的上下文有关(?) 全班(根据评论中的要求): 无法显示来自BroadcastReceiver和Service的对话框。请改为使用通知。无法在BroadcastReceiver中显示对话框。我也有同样的问题。我创建了一个活动,它继承了android的风格:style/Theme.Dialog。这使活
无法显示来自BroadcastReceiver和Service的对话框。请改为使用通知。无法在BroadcastReceiver中显示对话框。我也有同样的问题。我创建了一个活动,它继承了android的风格:style/Theme.Dialog。这使活动看起来像一个对话框 显示更多代码。你把这些代码放在哪里了。如果你的上下文没有问题就可以了。它位于
公共类MyC2DM extends BroadcastReceiver
内部私有void handleMessage(上下文上下文,意图)
。已将整个类添加到提交中。
AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
alertbox.setMessage("Received Push Notification");
alertbox.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
} });
AlertDialog alert = alertbox.create();
alert.show();
public class MyC2DM
extends BroadcastReceiver {
public MyC2DM()
{
}
@Override
public void onReceive(Context context, Intent intent)
{
Log.i("Recieve","2");
//Toast.makeText(context, "Intent Receive!", Toast.LENGTH_SHORT).show();
if (intent.getAction().equals("com.google.android.c2dm.intent.REGISTRATION"))
{
handleRegistration(context, intent);
}
else if (intent.getAction().equals("com.google.android.c2dm.intent.RECEIVE"))
{
handleMessage(context, intent);
}
}
private void handleRegistration(Context context, Intent intent)
{
String registration = intent.getStringExtra("registration_id");
if (intent.getStringExtra("error") != null)
{
Toast.makeText(context, "Reg Error!", Toast.LENGTH_LONG).show();
// Registration failed, should try again later.
}
else if (intent.getStringExtra("unregistered") != null)
{
// unregistration done, new messages from the authorized sender will be rejected
Toast.makeText(context, "Unreg!", Toast.LENGTH_LONG).show();
}
else if (registration != null)
{
// Send the registration ID to the 3rd party site that is sending the messages.
// This should be done in a separate thread.
// When done, remember that all registration is done.
// UserId = customer.getId();
// Log.i("id",String.valueOf(UserId));
String RegId = registration;
Log.i("reg",String.valueOf(RegId) );
}
}
private void handleMessage(Context context, Intent intent)
{
// Message handler.
Log.i("Recieve","MESSAGE");
AlertDialog.Builder alertbox = new AlertDialog.Builder(context);
alertbox.setMessage("Received Push Notification");
alertbox.setNeutralButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
} });
AlertDialog alert = alertbox.create();
alert.show();
/*Toast.makeText(context, "ALERT: " + intent.getStringExtra("payload"), Toast.LENGTH_LONG).show();*/
}
}