我试图显示通知类型的提示,但我做不到。我尝试过的
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
and NotificationCompat.Builder
SDK 示例不可用。有人知道该怎么做吗?
我通过添加以下内容使其工作:
.setDefaults(Notification.DEFAULT_VIBRATE)
这是最好的方法吗?
根据通知 http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Heads-up,您需要设置振动或铃声才能使平视功能发挥作用。但是,这里有一个不需要 VIBRATE 权限即可生成平视通知的快速技巧:
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
if (Build.VERSION.SDK_INT >= 21) notificationBuilder.setVibrate(new long[0]);
EDIT:
不要滥用抬头通知。看here https://www.google.com/design/spec/patterns/notifications.html#notifications-guidelines何时使用平视通知:
MAX:用于关键和紧急通知,提醒用户时间紧迫或需要解决才能继续执行特定任务的情况。
高:主要用于重要通信,例如包含用户特别感兴趣的内容的消息或聊天事件。高优先级通知会触发平视通知显示。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)