2013-02-22 71 views
0

我們嘗試實施本地通知擴展distriqt。Distriqt AIR本地通知Ane - 刪除舊通知

隨着停用事件新的通知設定:

notification.id  = int(Math.random()*100); 
        notification.tickerText = _asde + " asdasd!"; 
        notification.title  = _asde + " asd!"; 
        notification.body  = "asd!"; 
        notification.iconType = NotificationIconType.APPLICATION; 
        notification.count  = 0; 
        notification.repeatInterval = 0; 
        notification.vibrate = false; 
        notification.playSound = true; 
        notification.soundName = "assets/sounds/notification.mp3"; 

        notification.delay  = secondsToDeath; 
        notification.data  = "Some notification data to attach "+notification.id; 
try 
       { 
        Notifications.service.notify(notification.id, notification); 

        _count ++; 
        Notifications.service.setBadgeNumber(_count); 
       } 
       catch (e:Error) 
       { 

       } 

如果用戶點擊應用程序,並再次停用它,新的通知設定。

舊的通知仍然可用並顯示,但我們希望刪除舊的通知。 我們還沒有找到註銷舊通知的方法。

任何想法?

 private static const DEACTIVATE_NOTIFICATION_ID_4 : int = 4; 

已聲明。

if(_GoodA == true){ 
        setSpielenFertigDate.time = 2400000*(1-_aktuellerFreudeWert/_maximalerFreudeWert); 
        var secondsToSpielenFertig:int = int((setSpielenFertigDate.time)/ 1000); 

        trace("halloe" + _fernseherAn.toString()); 
        notification4.id  = DEACTIVATE_NOTIFICATION_ID_4; 
        notification4.tickerText = "He test it!"; 
        notification4.title   = "sdf is happy!"; 
        notification4.body  = "sdf test is on!"; 
        notification4.iconType = NotificationIconType.APPLICATION; 
        notification4.count  = 0; 
        notification4.repeatInterval = 0; 
        notification4.vibrate = false; 
        notification4.playSound = true; 
        notification4.soundName = "assets/sounds/notification.mp3"; 

        notification4.delay  = secondsToSpielenFertig; 
        notification4.data  = "Some notification data to attach "+ notification4.id; 

        try 
        { 
         Notifications.service.notify(notification4.id, notification4); 

         _count ++; 
         Notifications.service.setBadgeNumber(_count); 
        } 
        catch (e:Error) 
        { 

        } 
       } 
       else{ 
        trace("halloe2" + _fernseherAn.toString()); 
        setSpielenDate.time = 5100000*(_aktuellerFreudeWert/_maximalerFreudeWert); 
        var secondsToSpielen:int = int((setSpielenDate.time)/ 1000); 


        notification4.id  = DEACTIVATE_NOTIFICATION_ID_4; 
        notification4.tickerText = "He tested it!"; 
        notification4.title   = "sdf is unhappy!"; 
        notification4.body  = "sdf test is off!"; 
        notification4.iconType = NotificationIconType.APPLICATION; 
        notification4.count  = 0; 
        notification4.repeatInterval = 0; 
        notification4.vibrate = false; 
        notification4.playSound = true; 
        notification4.soundName = "assets/sounds/notification.mp3"; 
        //Sekunden bis Nachricht geschickt wird 
        notification4.delay  = secondsToSpielen; 
        notification4.data  = "Some notification data to attach "+notification4.id; 

        try 
        { 
         Notifications.service.notify(notification4.id, notification4); 

         _count ++; 
         Notifications.service.setBadgeNumber(_count); 
        } 
        catch (e:Error) 
        { 

        } 
       } 

如果應用程序的停用事件被觸發,它會跟蹤if和else子句的正確部分。但它不會更新正文和標題...

+0

你是在iOS還是Android? – Michael 2013-02-24 00:58:36

回答

0

有兩種方法可以用我們的擴展程序來做到這一點。兩者都涉及跟蹤通知的ID。

首先是跟蹤您的上次通知並從通知區域「取消」它。爲此,您需要至少存儲上次創建的通知的ID。您可能感興趣的部分代碼是取消函數,它通過指定要刪除的通知的ID來從通知面板中刪除通知。

某處在您的類中聲明的最後通知的參考:

private var _lastNotification : Notification; 

然後在您的停用處理程序:

var notification:Notification = new Notification(); 
notification.id = int(Math.random()*100); 
notification.tickerText = "Deactivated"; 
notification.title = "TEST"; 
notification.body = "Application Deactivated"; 

if (_lastNotification != null) 
    Notifications.service.cancel(_lastNotification.id); 
Notifications.service.notify(notification.id, notification); 

// Set this to be the recent notification displayed 
_lastNotification = notification; 

第二個選擇是使用單一的通知ID爲您的所有停用通知。在這種情況下,您可以選擇一個常量ID用於通知,並根據需要更新通知。通知管理器不會顯示附加通知,只需更新具有指定標識的通知(或者如果已被用戶關閉,則顯示該通知)。

private static const DEACTIVATE_NOTIFICATION_ID : int = 10; 

var notification:Notification = new Notification(); 
notification.id = DEACTIVATE_NOTIFICATION_ID; 
notification.tickerText = "Deactivated"; 
notification.title = "TEST"; 
notification.body = "Application Deactivated"; 

Notifications.service.notify(notification.id, notification); 

希望這會有所幫助!

+0

謝謝!這是我尋找的第二部分。我知道取消功能,但不能用此刪除活動的通知。所以我不得不重寫這些值。它現在更新Notification.delay。但它不會更新Notification.body? – 2013-02-25 11:15:47

+0

如何更新Notification.body和Notification.title? – 2013-02-26 15:22:28

+0

如果您使用的是常量ID方法,那麼只需在新通知中指定一個新正文和標題,即可更新現有相同ID的通知。 – Michael 2013-02-27 01:16:53