繁体   English   中英

Android:向状态栏添加通知

[英]Android: Adding notification to status bar

我已经使用NotificationCompat.Builder创建了一个通知,但我不知道如何在状态栏中显示它。 我试过用

NotificationManager notificationManager = (NotificationManager)
                               getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(mId, mBuilder.build());

但它不适用于2.2所以我需要另一种方式......

这是我的通知

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.notification)
            .setContentTitle("Message")
            .setContentText("Notification");

但它不适用于2.2

是的,它确实。

此示例应用程序显示了一个IntentService下载文件并显示Notification使用NotificationCompat.Builder 它使用与您的代码非常相似的代码来实际提升Notification

NotificationManager mgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mgr.notify(NOTIFY_ID, b.build());

这段代码在Android 2.2上工作正常,因为我在模拟器上再次尝试(并再次),并且Notification按预期显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM