2
我想了解有關指示燈以及如何使用它們的更多信息,所以我創建了一個應用程序以在不同的通知出現時使指示燈閃爍不同的顏色。問題是,如果一個通知已經在控制指示燈,我不能做我自己的事情,是否有阻止來自它的其他應用程序或覆蓋它們?如何讓Android應用程序優先使用指示燈
這是我通知偵聽器
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());
}
}