android通知横幅不显示

时间:2014-06-30 19:32:20

标签: java android

由于某种原因,当我在我的应用程序中显示通知时会振动并产生噪音,但手机顶部没有横幅。我需要一个特定的命令才能做到这一点吗?

public Notification getNotification(String message) {
        Intent intent = new Intent(serviceContext,     NotificationGenerator.class); //not sure how
        // this class i pass matters
        PendingIntent pi = PendingIntent.getActivity(serviceContext, 0, intent, 0);
        NotificationCompat.Builder builder = new     NotificationCompat.Builder(serviceContext)
            .setContentTitle(message)
            .setContentText(message)
            .setSmallIcon(R.drawable.dominos_icon)
            .setContentIntent(pi);
        Notification n = builder.build();
        n.defaults = Notification.DEFAULT_ALL;
        return n;
    }

1 个答案:

答案 0 :(得分:0)

一旦您添加以下行,您的代码就可以正常工作:

NotificationManager n_mngr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
n_mngr.notify(NOTIF_ID, n);