android 通知灯 测试,Android – 如何有LED灯通知?

更新:在Android 3.0之前,我正在修改原始帖子以实现兼容性。

我试图创建一个简单的通知,除了光之外的一切都很好。当通知触发时,屏幕关闭。使用这种不推荐的代码声音和震动在Android 4.0(Galaxy Nexus)和Android 2.3(HTC EVO)上起作用。

>在2.3 HTC EVO上,灯也可以工作。

>在4.0 Galaxy Nexus上,灯不起作用。

Notification notification =

new Notification(R.drawable.ic_launcher, "My Ticker!",System.currentTimeMillis());

notification.setLatestEventInfo(context, "My Title", "My Message", pendingIntent);

notification.defaults |= Notification.DEFAULT_SOUND;

notification.defaults |= Notification.DEFAULT_VIBRATE;

//notification.defaults |= Notification.DEFAULT_LIGHTS;

notification.ledARGB = 0xff00ff00;

notification.ledOnMS = 300;

notification.ledOffMS = 1000;

notification.flags |= Notification.FLAG_SHOW_LIGHTS;

notification.flags |= Notification.FLAG_AUTO_CANCEL;

我也尝试了不是v4兼容性库的一部分的新API,所以我只能在Galaxy Nexus上测试。振动和声音再次起作用,但不起作用。

Notification.Builder builder = new Notification.Builder(context);

builder.setContentIntent(pendingIntent)

.setSmallIcon(R.drawable.ic_launcher)

.setTicker("My Ticker")

.setWhen(System.currentTimeMillis())

.setAutoCancel(true)

.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)

.setLights(0xff00ff00, 300, 100)

.setContentTitle("My Title 1")

.setContentText("My Text 1");

Notification notification = builder.getNotification();

我现在已经在两款Galaxy Nexus手机上进行了测试,而这两款手机都没有。当我运行测试时,屏幕关闭,手机上的所有其他应用程序都会触发灯,而不会出现问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值