2013-12-20 22 views
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()); 

    } 

} 

回答

1

代碼我創建一個應用程序,以閃爍的指示燈不同顏色時,不同的通知顯示

這是不可能很好地工作。例如,您不能將指示燈添加到缺少硬件的指示燈,也不能將您的應用過濾爲僅適用於具有指示燈的設備。

是否有阻止來自它的其他應用程序或重寫它們?

不可以。您也不能阻止設備使用指示燈用於其他目的,例如充電狀態。

相關問題