简体   繁体   English

推送到达时显示警报

[英]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.

相关问题 Flutter - 推送通知到达时在应用程序图标上显示徽章编号 - Flutter - Display badge number on app icon when push notification arrives 当推送到达时,将cordova应用程序带到前台 - Bring cordova application to foreground when push arrives 当应用程序在前台运行时,在警告框中显示推送通知 - Display push notification in alert box when the app is running in the foreground 推送通知到达时转到特定路径(Angular,Ionic,ngcordova) - Goto particular path when push notification arrives (Angular, Ionic, ngcordova) Worklight 6.1-Android推送通知到达时无声音 - Worklight 6.1 - No Sound When Android Push Notification Arrives 如何显示来自推送通知FCM的警报 - How to display an alert from push notification fcm 在后台并且推送通知到达时,使用Phonegap PushPlugin无法打开应用程序 - Using Phonegap PushPlugin does not open App when in background and Push Notification arrives 当推送消息到达时,通知正在运行的应用程序更新数据的正确方法是什么? - What is the correct aproach to notify running application to update data when a push message arrives? 没有互联网连接时显示警报消息 - Display alert message when there's no internet connectivity 当活动onPause()时显示警报对话框 - Display Alert Dialog when Activity onPause()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM