【发布时间】:2014-10-19 15:08:33
【问题描述】:
我正在尝试显示通知类型的提示,但我不能。我尝试了什么
final Notification.Builder notif = new Builder(getApplicationContext())
.setContentTitle(getString(R.string.title))
.setContentText(getString(R.string.text))
// .setTicker(getString(R.string.tick)) removed, seems to not show at all
// .setWhen(System.currentTimeMillis()) removed, match default
// .setContentIntent(contentIntent) removed, I don't neet it
.setColor(Color.parseColor(getString(R.color.yellow))) //ok
.setSmallIcon(R.drawable.ic_small) //ok
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
// .setCategory(Notification.CATEGORY_CALL) does not seem to make a difference
.setPriority(Notification.PRIORITY_MAX); //does not seem to make a difference
// .setVisibility(Notification.VISIBILITY_PRIVATE); //does not seem to make a difference
mNotificationManager.notify(Constants.NOTIFICATION_ID, notif.build());
通知仅在栏中显示为图标。
我在 API 21 模拟器上使用 API 21(不是 L 预览版)
我试过了:android:Theme.Holo.NoActionBar,android:Theme.Holo.NoActionBar.Fullscreen
和NotificationCompat.Builder
SDK 示例不可用。有人知道怎么做吗?
我通过添加:
使其工作.setDefaults(Notification.DEFAULT_VIBRATE)
这是最好的方法吗?
【问题讨论】:
-
如果这对您有用,那么您应该将其添加为答案。
-
请注意,在观看媒体或使用任何应用程序时,提醒通知可能会非常烦人 - 毫不奇怪,几乎每个应用程序都使用屏幕顶部。它们在屏幕的顶部三分之一处投下阴影(在我的 8" Tegra Shield 上测试)。如果您必须使用这些(天知道为什么),请至少在您的应用中禁用它们!
-
@user1499731 Android 原生支持禁用应用 IIRC 的通知窥视。
-
setDefaults(Notification.DEFAULT_VIBRATE) 有效
-
我已经在medium.com/@md.noor.asad/…发布了一个关于显示提醒通知的简介
标签: android android-5.0-lollipop android-notifications