【问题标题】:Show Dialog when touch notification on Android在 Android 上触摸通知时显示对​​话框
【发布时间】:2016-12-13 03:34:50
【问题描述】:

我已经在 Eclipse 项目上使用 Firebase Cloud Messaging 构建了推送通知。现在,当我触摸状态栏上的通知时,我想用 OK 按钮进行对话框。

谁能帮帮我?或建议如何处理? 仅供参考,任何时候(当应用程序在后台或前台时)如果我触摸顶部的通知,它将显示一个对话框。

非常感谢。

【问题讨论】:

    标签: android firebase android-notifications firebase-cloud-messaging


    【解决方案1】:

    首先,您需要在通知中使用待定意图,定义如何处理通知点击。

        Intent notificationIntent = new Intent(this, DialogActivity.class);
        PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    
        Notification notification = new Notification.Builder(this)
                 // YOUR Notification parameters
                .build();
    
        notification.contentIntent = pendingNotificationIntent;
    

    看到intent指向了一个DialogActivity,所以我们需要创建一个DialogActivity来处理这个intent。请看下面的代码:

    public class DailogActivity extends Activity {
    
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    
        // Get Extra data from intent if you pass something
        // Intent intent = getIntent();
        // Bundle extras = intent.getExtras();
    
        // Show the popup dialog
        showNewDialog(0);
    }
    
    public void showNewDialog(int id) {
        // TODO : Code to show the new dialog
    }
    }
    

    【讨论】:

    • 谢谢大佬,我先试试。 :)
    • 你能解释一下,在哪里使用 DialogActivity 上的 'pendingNotificationIntent'?
    • 它不是必需的,pendingNotification 意图只是与通知一起使用,来处理它的动作。
    • 我仍然无法弹出对话框,先生。
    • 您面临的问题是什么?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多