FCM 推送通知在安卓 4.4 上不起作用



我有一个应用程序,然后当针对android 8.0编译完美运行时,在手机的通知中心获取通知。

但是如果针对android 4.4编译不起作用,(不要收到通知(

使用本文档: https://learn.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/firebase-cloud-messaging

代码 =>https://github.com/franciscom95/FcmXamarinTest

请尝试浏览以下代码,希望对您有所帮助,我目前正在这样使用。

public void showNotification(String message, String title, String action, String value, boolean isImageUrl, String CHANNEL_ID, String BADGE_NUMBER) throws CleverTapPermissionsNotSatisfied, CleverTapMetaDataNotFoundException {
    if (!TextUtils.isEmpty(message)) {
        Intent mainIntent = new Intent(this, HomeScreen.class);
        if (notification_key_values.containsKey(action.toLowerCase())) {
            mainIntent.putExtra("FromPushNotification", true);
            mainIntent.putExtra("PushAction", action);
            if (!isImageUrl) {
                String hash_value = notification_key_values.get(action.toLowerCase());
                if (!hash_value.isEmpty()) {
                    updateNotification(message, hash_value, action, value, extras.getString("TokenId"), extras.getString("SegmentId"), extras.getString("Action"));
                }
            }
            if (action.toLowerCase().equals("redirectionurl")) {
                mainIntent.putExtra("PushValue", value);
            }
        } else {
            if (!isImageUrl) {
                updateNotification(message, action, action, value, "", "", "");
                mainIntent.putExtra("FromPushNotification", true);
                mainIntent.putExtra("PushAction", action);
            } else {
                mainIntent.putExtra("FromPushNotification", false);
            }
        }
        mainIntent.putExtras(extras);
        mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mainIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        stackBuilder.addNextIntent(mainIntent);
        PendingIntent launchIntent;
        launchIntent = stackBuilder.getPendingIntent((int) System.currentTimeMillis(), PendingIntent.FLAG_UPDATE_CURRENT
                | PendingIntent.FLAG_ONE_SHOT);
        Notification notification;
        setLargeIcon = BitmapFactory.decodeResource(this.getResources(),
                R.drawable.appicon);
        Uri notification_sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            CleverTapAPI cleverTapAPI = CleverTapAPI.getInstance(this);
            cleverTapAPI.createNotificationChannel(getApplicationContext(), CHANNEL_ID, CHANNEL_NAME, " ", NotificationManager.IMPORTANCE_HIGH, false);
            NotificationCompat.Builder builder = new NotificationCompat.Builder(this, this.CHANNEL_ID);
            builder.setSmallIcon(getSmallIcon());
            builder.setLargeIcon(setLargeIcon);
            builder.setStyle(style);
            builder.setContentTitle(title);
            builder.setContentText(message);
            notification = builder.build();
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.contentIntent = launchIntent;
            NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(this);
            notificationManagerCompat.notify((int) System.currentTimeMillis(),notification );
        } else {
            if (Build.VERSION.SDK_INT == Build.VERSION_CODES.LOLLIPOP) {
                notification = new NotificationCompat.Builder(this)
                        .setSmallIcon(getSmallIcon())
                        .setLargeIcon(setLargeIcon)
                        .setContentTitle(
                                title)
                        .setContentText(message)
                        .setColor(this.getResources().getColor(R.color.position_blue))
                        .setStyle(style)
                        .setSound(notification_sound)
                        .setAutoCancel(true).build();
            } else {
                notification = new NotificationCompat.Builder(this)
                        .setSmallIcon(getSmallIcon())
                        .setContentTitle(
                                title)
                        .setContentText(message)
                        .setStyle(style)
                        .setSound(notification_sound)
                        .setAutoCancel(true).build();
                NotificationCompat.BigTextStyle().bigText(message))
            }
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.contentIntent = launchIntent;
            NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
            notificationManager.notify((int) System.currentTimeMillis(), notification);
        }
    }
}

}

相关内容

  • 没有找到相关文章

最新更新