2017-08-07 192 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

只是等待一分钟 –