android通知LED灯光控制

public void onClick(View v) {
switch (v.getId()) {
case R.id.send_notice:
Intent intent = new Intent(MainActivity.this, NotificationActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notification = null;
notification = new NotificationCompat.Builder(this)
.setContentTitle("This is content title")
.setContentText("This is content text")
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher))
.setContentIntent(pi)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM)) //声音
.setVibrate(new long[]{0, 500, 100, 500, 100, 500}) //节奏震动
.setLights(0xFFFFFF00, 1000, 1000) //LED灯闪
.build();

            manager.notify(1, notification);
            break;
        default:
            break;
    }
}

触发之后,系统默认闹钟声音、带节奏的震动,如果这时候你锁屏,就可以看到LED灯闪的效果了。
0xFFFFFF00 使用十六进制颜色值来控制颜色

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容