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 使用十六进制颜色值来控制颜色