gpt4 book ai didi

java - 如何让android应用程序优先使用指示灯

转载 作者:行者123 更新时间:2023-11-30 11:24:17 24 4
gpt4 key购买 nike

我想了解更多关于指示灯以及如何使用它们的信息,所以我正在创建一个应用程序,当出现不同的通知时,指示灯会闪烁不同的颜色。问题是,如果通知已经在控制指示灯,我不能做我自己的事情,有没有办法阻止其他应用程序访问它或覆盖它们?

这是我的通知监听器代码

public class NotificationListener extends NotificationListenerService
{
private final String TAG = "NotificationListenerTestingTag";
private NotificationManager notifMgr;

@Override
public void onCreate()
{
super.onCreate();
Log.v(TAG, "Service Created");

// Get the Notification Manager
notifMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}

@Override
public void onNotificationPosted(StatusBarNotification n)
{
Log.i(TAG, "Notification Posted: " + n.getPackageName());

// Turn on indicator light
Notification ledControll = new Notification();
ledControll.ledARGB = Color.argb(255, 0, 255, 0);
ledControll.flags |= Notification.FLAG_SHOW_LIGHTS;
ledControll.priority = Notification.PRIORITY_MAX;
ledControll.ledOnMS = 200;
ledControll.ledOffMS = 300;

notifMgr.notify(n.hashCode(), ledControll);

}

@Override
public void onNotificationRemoved(StatusBarNotification n)
{
Log.i(TAG, "Notification Removed: " + n.getPackageName());

// Turn off indicator light
notifMgr.cancel(n.hashCode());

}

}

最佳答案

i am creating an app to blink the indicator light different colors when different notifications appear

这不太可能奏效。例如,您不能为缺少指示灯的硬件添加指示灯,也不能将您的应用程序过滤为仅适用于具有指示灯的设备。

is there anyway to block other applications from it or override them?

没有。您也无法阻止设备将指示灯用于其他目的,例如充电状态。

关于java - 如何让android应用程序优先使用指示灯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20708491/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com