[英]Display Alert when push arrives
How Can I Display an alert when push notification arrives from C2DM or GCM. 如何从C2DM或GCM到达推送通知时显示警报。 Right now I am displaying notifications on status bar.
现在我正在状态栏上显示通知。 So How can I get a notification as an alert.
那么如何将通知作为警报获取。
Popping a dialog in the middle of something a user is doing is a wildly user hostile thing to do. 在用户正在做的事情中弹出一个对话框是一个非常用户的敌对事情。 What if they're playing Angry Birds and you've just ruined their shot?
如果他们在玩“愤怒的小鸟”并且你们刚刚毁掉他们的射击怎么办? Only the platform can and should get away with that.
只有平台可以而且应该侥幸逃脱。
Use the notification area, like Google intended, UNLESS you app currently has control (your activity is in running state). 除非您的应用当前拥有控制权(您的活动处于运行状态),否则请使用Google预期的通知区域。 Then just use that activity's context to pop an
AlertDialog()
. 然后只需使用该活动的上下文来弹出
AlertDialog()
。 You can detect if the activity is running by overriding onResume()
and onPause()
- anything that happens in between is your activity's time. 您可以通过覆盖
onResume()
和onPause()
来检测活动是否正在运行 - 中间发生的任何事情都是您的活动时间。
An AlertDialog can be popped like this: 可以像这样弹出AlertDialog:
new AlertDialog.Builder(Ctxt) //Use an activity object here
.setMessage(R.string.MyMessageID) //Provide a message here... A string or a string ID will do
.setCancelable(true) //If you want them to be able to dismiss with a Back button
.setNegativeButton(R.string.IDS_NO, null) //No action on NO, right?
.setPositiveButton(R.string.IDS_YES, OnYesClickListener) //Plug your own listener...
.create()
.show();
For a simple message/Yes/No dialog, an AlertDialog
would suffice. 对于简单的消息/是/否对话框,
AlertDialog
就足够了。 For more complicated UI, derive a class from Dialog
and design your own layout. 对于更复杂的UI,从
Dialog
派生一个类并设计自己的布局。
For Alert you need to write code in 对于Alert,您需要编写代码
generateNotification(Context context, String message) generateNotification(上下文上下文,字符串消息)
in this method. 在这种方法中。
Thanks 谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.