【发布时间】:2018-01-09 13:12:15
【问题描述】:
我正在尝试打开/关闭按钮单击时的 LED。但根据this ,它适用于通知。我已经尝试过,它正在处理通知。我想在没有通知的情况下打开/关闭 LED。到目前为止,我尝试过的如下:
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);
// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject").setSmallIcon(R.mipmap.ic_launcher)
.setContentIntent(pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL|Notification.FLAG_SHOW_LIGHTS;
noti.ledARGB = Color.RED;
noti.ledOnMS = 100;
noti.ledOffMS = 100;
notificationManager.notify(0, noti);
当屏幕关闭并且我已经运行应用程序时它正在工作。有人可以帮我这样做吗?谢谢。
【问题讨论】:
-
您可以发布您尝试过的内容吗?
-
上面的代码在通知中使用,它根据你的问题工作,你在没有通知的情况下尝试了什么。
-
我没有其他方法可以做到这一点。
标签: android android-camera led