2017-08-07 90 views
0

我想在應用程序處於前景以及背景時使用Firebase發送通知。我能夠實現這一點,但問題是,而不是默認的Firebase通知圖標(一些白色的方形圓圈),我想我的發射器圖標顯示。我已經實現了以下代碼,但仍未顯示。我不知道這裏有什麼問題。下面是代碼FirebaseMessagingServiceFirebase通知未顯示圖標

public class MyFirebaseMessagingService extends FirebaseMessagingService { 

    @Override 
    public void onMessageReceived(RemoteMessage remoteMessage) { 
     Intent intent = new Intent(this, MainActivity.class); 
     intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
     PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT); 

     NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this); 
     notificationBuilder.setContentTitle("Dream 11 Prediction Guru"); 
     notificationBuilder.setContentText(remoteMessage.getNotification().getBody()); 
     notificationBuilder.setAutoCancel(true); 
     notificationBuilder.setSmallIcon(R.mipmap.ic_launcher_round); 
     //notificationBuilder.setLargeIcon(R.mipmap.ic_launcher); 
     notificationBuilder.setContentIntent(pendingIntent); 

     NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     notificationManager.notify(0,notificationBuilder.build()); 
    } 

} 

FirebaseInstanceIdService代碼

public class MyFirebaseInstanceIdService extends FirebaseInstanceIdService { 

    private static final String REG_TOKEN = "REG_TOKEN"; 

    @Override 
    public void onTokenRefresh() { 
     String recent_token = FirebaseInstanceId.getInstance().getToken(); 
     Log.d(REG_TOKEN,recent_token); 
    } 

} 

enter image description here

enter image description here

+0

您是使用Firebase控制檯發送推送通知還是實施服務器端? –

+0

使用Firebase控制檯發送消息 –

回答

0

嘗試清單文件中添加此:

<meta-data 
      android:name="com.google.firebase.messaging.default_notification_icon" 
      android:resource="@mipmap/ic_launcher" /> 
+0

嘗試過,但它仍然不能正常工作 –

+0

您可以在您的問題中添加您問題的圖片,我需要看看真正發生了什麼,謝謝。 @NikeshPatel –

+0

只是等待一分鐘 –