首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FCM推送通知在Android 4.4上不起作用

FCM推送通知在Android 4.4上不起作用
EN

Stack Overflow用户
提问于 2019-03-23 10:36:49
回答 1查看 375关注 0票数 1

我有一个应用程序,然后当编译android 8.0完美工作时,在手机的通知中心得到通知。

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

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

Code => https://github.com/franciscom95/FcmXamarinTest

EN

回答 1

Stack Overflow用户

发布于 2019-03-23 17:16:14

尝试通过下面的代码,希望这能帮助你,我目前正在使用这样的代码。

代码语言:javascript
运行
复制
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);
        }
    }
}

}

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55310074

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档