【问题标题】:Displaying a notification in android在android中显示通知
【发布时间】:2012-08-04 13:28:38
【问题描述】:

我正在使用以下代码在我的 android 应用程序中显示通知,但是使用此代码,通知也会显示活动(即黑色空白屏幕)我不想要这个屏幕,而只是一个简单的通知以及何时用户点击通知然后我想启动活动。这段代码应该怎么做?

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        Notification notify = new Notification(R.drawable.mcube_logo, "Message Sent", Calendar.getInstance().getTimeInMillis());

        Intent intent = new Intent(RecieveAlarm.this, otherActivity.class);
        PendingIntent pendingIntent =PendingIntent.getActivity(RecieveAlarm.this, 1, null, PendingIntent.FLAG_CANCEL_CURRENT);

        notify.setLatestEventInfo(RecieveAlarm.this, "Title", "Details", pendingIntent);
        notificationManager.notify(0, notify);

【问题讨论】:

    标签: android android-intent android-emulator android-widget


    【解决方案1】:

    我建议你使用:

            Notification not = new Notification(idIcon, text, System.currentTimeMillis());
        PendingIntent pInt = PendingIntent.getActivity(ctx, 0, new Intent(ctx, the_class_to_call), 0);
    
        not.setLatestEventInfo(ctx, app_name, text, pInt);
    

    然后not.notify....

    【讨论】:

      【解决方案2】:

      使用 AlertDialog,然后在点击肯定按钮时启动所需的活动

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-09
        • 1970-01-01
        • 2017-03-02
        • 2019-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多