通知setLights()是否为默认值?
社区首页 >问答首页 >通知setLights()是否为默认值?问通知setLights()是否为默认值?ENStack Overflow用户提问于 2013-02-27 18:22:02回答 3查看 15.3K关注 0票数 9我想创建自定义通知。所以我想改变灯光和音调。我使用NotificationCompat.Builder来实现这一点。
现在,我想通过setLights()更改灯光;效果很好。但是我想设置onMS和offMS的默认值。我还没有找到关于那个的任何东西。
有没有人能帮我找出默认值?下面是相关的文档:http://developer.android.com/reference/android/support/v4/app/NotificationCompat.Builder.html#setLights(int, int, int)
notificationsandroid-notificationsandroid关注问题分享EN回答 3推荐最新Stack Overflow用户发布于 2015-12-10 15:11:53
有关答案,请参阅Android source:
代码语言:javascript复制
代码语言:javascript复制Resources resources = context.getResources(),
systemResources = Resources.getSystem();
notificationBuilder.setLights(
ContextCompat.getColor(context, systemResources
.getIdentifier("config_defaultNotificationColor", "color", "android")),
resources.getInteger(systemResources
.getIdentifier("config_defaultNotificationLedOn", "integer", "android")),
resources.getInteger(systemResources
.getIdentifier("config_defaultNotificationLedOff", "integer", "android")));根据diff的说法,这些属性保证在安卓2.2+ (接口级8+)上存在。
收藏分享票数 8ENStack Overflow用户发布于 2013-02-27 19:52:34
@Aleks G无济于事。我从图书馆得到了最新的更新。但是Eclipse说build()是不可用的。我不知道为什么。文件说可以然后你..。
这是我当前的代码:
代码语言:javascript复制 NotificationCompat.Builder notify = new NotificationCompat.Builder(context);
notify.setLights(Color.parseColor(led), 5000, 5000);
notify.setAutoCancel(true);
notify.setSound(Uri.parse(tone));
notify.setSmallIcon(R.drawable.ic_stat_kw);
notify.setContentTitle("Ttiel");
notify.setContentText("Text");
Intent showIntent = new Intent(context, Activity_Login.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, showIntent, 0);
notify.setContentIntent(contentIntent);
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notify.getNotification());运行得很完美。但不使用setLights()中的默认onMS和offMS :(
收藏分享票数 2ENStack Overflow用户发布于 2013-02-27 18:34:58
您应该能够使用以下命令来执行此操作:
代码语言:javascript复制Notifictaion notf = new Notification.Builder(this).setXXX(...).....build();
notf.ledARGB =
notf.ledOnMS =
notf.ledOffMS =
这是我的示例项目的实际复制/粘贴,它在Android2.1上编译和工作得很好,并使用蓝色的:
代码语言:javascript复制Notification notf = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setTicker("This is the sample notification")
.setSmallIcon(R.drawable.my_icon)
.build();
notf.ledARGB = 0xff0000ff;
NotificationManager mNotificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(1, notf);收藏分享票数 1EN页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持原文链接:https://stackoverflow.com/questions/15109593
复制相关文章