【问题标题】:How to on/off LED in android not flash light?如何在android中打开/关闭LED而不是闪光灯?
【发布时间】: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


【解决方案1】:

除了 Notification 类之外,我还没有看到任何用于处理 LED 的 API,因为它是内置的,并且完全由基于硬件的处理,所以只有 Notification 类 可以处理它。所以请不要'不要浪费时间去搜索它。

希望你能理解。

【讨论】:

  • 我已经得到了一两个地方,但我需要它用于条形码扫描仪。
  • 所以你只需要使用那些只提供处理它的通知类。所以请关闭你的问题,因为没有任何其他解决方案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 2013-06-20
  • 1970-01-01
  • 2011-08-18
  • 2012-11-05
  • 1970-01-01
相关资源
最近更新 更多