2016-05-13 51 views
0

我實際上使用PushBots來爲我的應用程序實現GCM通知。如何在收到的Android通知中設置默認的smallIcon和largeIcon?

當我創建通知時,他們給我的選項是使用特定的字段,我可以爲我的推送設置largeIcon。如果我使用,我得到的是這樣的:

enter image description here

但是,如果我不使用,我得到這樣的:

enter image description here

我想知道,如果是有可能爲每個通知(推送)設置默認的smallIconlargeIcon,以便我的應用程序接收或更改爲我自己的應用程序圖標顯示的白色框。

1注:我沒有在我的代碼創建的通知,我在PushBots網站Drashboard創建它。

2 - 注:largeIconsmallIcon

enter image description here

感謝。

回答

0

最後,在查看了PushBot的源代碼後,我找到了一個解決方案。

在Android Studio中,轉至File -> New -> Image Asset。然後,選擇Notification Icon。現在自定義您的新小圖標,並在完成之前爲此新資產命名爲white_notification_icon

Android Studio會告訴你,該文件已經存在,它將被覆蓋。說是的。

現在,你有一個smallIcon默認情況下已經設置!

0

請參考下面的代碼

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this); 
    mBuilder.setSmallIcon(R.drawable.small_notification); 
    mBuilder.setLargeIcon(BitmapFactory.decodeResource(getBitmapFromURL("YOURURL")); 

    if (version >= 23) { 
     mBuilder.setColor(ContextCompat.getColor(this, R.color.black)); 
    } else { 
     mBuilder.setColor(this.getResources().getColor(R.color.black)); 
    } 

作爲每引導線小圖標是強制性的,應該是在白色或灰色用α回地面refer this answer for more details

+0

它不工作。 –

+0

是的,它適用於我的情況只是把你的圖標路徑正確 –

+0

我必須把這個代碼在哪裏?在我的MainActivity.java中? –

相關問題