2016-10-29 26 views
0

我的Android GCM實現有一個奇怪的問題。手動處理每個GCM推送的正確方法是什麼?

這是我處理GCM通知代碼:

public class GCMMessageHandler extends GcmListenerService { 

    @Override 
    public void onMessageReceived(String from, Bundle data) { 
     super.onMessageReceived(from, data); 
     Log.i(this.getClass().getSimpleName(), "GCM push received!"); 

     ACNotification notification = new ACNotification(getApplicationContext(), data); 
     notification.handleNotification(); 
    } 
} 

基本上,這是什麼呢,它通知數據傳遞給我的課叫ACNotification,然後讀取數據,並顯示使用Notification.Builder的通知。

當應用程序處於前景時,此功能完美無缺。但是,一旦用戶關閉應用程序,似乎這個代碼永遠不會執行,但應用程序以某種方式自行處理通知。

它仍然顯示通知,但Android自己做。它沒有設置正確的通知圖標(它只是使用Android股票ic_launcher圖標)。

任何想法我做錯了什麼?我如何確保自己能夠處理每個通知?

+0

有點模糊。根據您的行爲,您在有效負載中使用「通知」和「數據」。如果是這樣,這是預期的行爲。點擊應用程序後,您必須從意圖獲取數據。 –

回答

相關問題