【问题标题】:How to get the icon to display for push notification message [duplicate]如何获取图标以显示推送通知消息[重复]
【发布时间】:2017-12-22 15:19:13
【问题描述】:

如何让我的图标显示在 android 中的推送通知消息旁边。我有一个 cordova 应用程序,我看到 iOS 推送消息的图标,但在 Android 上,我的推送消息旁边有一个白色圆圈。

我的 config.xml 文件中有这个设置

<platform name="android">

        <icon src="splash/icon/android/icon-96-xhdpi.png" />
        <icon density="ldpi" src="splash/icon/android/icon-36-ldpi.png" />
        <icon density="mdpi" src="splash/icon/android/icon-48-mdpi.png" />
        <icon density="hdpi" src="splash/icon/android/icon-72-hdpi.png" />
        <icon density="xhdpi" src="splash/icon/android/icon-96-xhdpi.png" />
        <icon density="xxhdpi" src="splash/icon/android/icon-144-xxhdpi.png" />
        <icon density="xxxhdpi" src="splash/icon/android/icon-192-xxxhdpi.png" />

    </platform>

感谢您的帮助

【问题讨论】:

    标签: android cordova ibm-mobilefirst


    【解决方案1】:

    您好,您只需从 onMessageReceived() 中调用此方法 MyFirebaseMessagingService 您可以获得通知图标而不是 白色图标。希望这可能对您有所帮助。这是针对安卓的。像这样:-Icon not displaying in notification: white square shown instead

    private void sendNotification(String message, String mAction) {
            int id = (int) System.currentTimeMillis();
            PendingIntent pendingIntent = null;
            Intent intent = new Intent(this, SplashActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | 
            Intent.FLAG_ACTIVITY_SINGLE_TOP);
            pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT);
    
            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                    .setSmallIcon(R.mipmap.ic_launcher)
                    .setContentTitle(getString(R.string.app_name))
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setContentIntent(pendingIntent);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
            } else {
                notificationBuilder.setSmallIcon(R.mipmap.ic_launcher);
            }
            NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify(id, notificationBuilder.build());
        }
    

    【讨论】:

    • 请不要复制其他问题的答案。正确的回答是将此问题标记为重复。
    猜你喜欢
    • 2017-03-16
    • 2018-01-21
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多