当前位置: 首页>>代码示例>>Java>>正文


Java RemoteMessage.Notification方法代码示例

本文整理汇总了Java中com.google.firebase.messaging.RemoteMessage.Notification方法的典型用法代码示例。如果您正苦于以下问题:Java RemoteMessage.Notification方法的具体用法?Java RemoteMessage.Notification怎么用?Java RemoteMessage.Notification使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.messaging.RemoteMessage的用法示例。


在下文中一共展示了RemoteMessage.Notification方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: displayNotification

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Muestra que ha habido una nueva notificación
 * @param notification
 * @param data
 */
private void displayNotification(RemoteMessage.Notification notification, Map<String, String> data) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("notificacion","notificacion");
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setContentTitle(notification.getTitle())
            .setContentText(notification.getBody())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setSmallIcon(R.mipmap.ic_launch)
            .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());
}
 
开发者ID:nen155,项目名称:TFG-SmartU-La-red-social,代码行数:27,代码来源:MyFirebaseMessagingService.java

示例2: sendNotification

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Create and show a simple notification containing the received FCM message.
 *
 * @param messageBody FCM message body received.
 */
private void sendNotification(RemoteMessage.Notification messageBody) {
    System.out.println("SEND NOTIFICATION CALLED");
    Intent intent = new Intent(this, SplashActivity.class);
    System.out.println(messageBody.getBody());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent 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(messageBody.getTitle())
            .setContentText(messageBody.getBody())
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
 
开发者ID:rohansapre,项目名称:cleanhood,代码行数:28,代码来源:PushMessagingService.java

示例3: parseColor

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Nullable
private Integer parseColor(RemoteMessage.Notification fcmNotification) {
    String notificationColor = fcmNotification.getColor();

    Integer color = null;
    if (notificationColor != null) {
        try {
            color = Color.parseColor(notificationColor);
        } catch (IllegalArgumentException ignore) {
        }
    }
    if (color == null) {
        int colorResId = getResourceIdFromApplicationMetadata("com.google.firebase.messaging.default_notification_color");
        if (colorResId != 0)
            color = ContextCompat.getColor(context, colorResId);
    }
    return color;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:19,代码来源:RemoteMessageToNotificationMapper.java

示例4: onMessageReceived

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Called when a message is received.
 *
 * @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
 */
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
    String title;
    String text;
    String id;
    Map<String, String> data = remoteMessage.getData();
    RemoteMessage.Notification notification = remoteMessage.getNotification();

    if (notification != null) {
        title = notification.getTitle();
        text = notification.getBody();
        id = remoteMessage.getMessageId();
    } else {
        title = data.get("title");
        text = data.get("text");
        id = data.get("id");
    }

    if (TextUtils.isEmpty(id)) {
        Random rand = new Random();
        int n = rand.nextInt(50) + 1;
        id = Integer.toString(n);
    }

    Log.i(TAG, "From: " + remoteMessage.getFrom());
    Log.i(TAG, "Notification Message id: " + id);
    Log.i(TAG, "Notification Message Title: " + title);
    Log.i(TAG, "Notification Message Body/Text: " + text);

    if (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title) || (!remoteMessage.getData().isEmpty())) {
        boolean showNotification = (Firebase.inBackground() || !MessagingComponent.hasNotificationsCallback())
                && (!TextUtils.isEmpty(text) || !TextUtils.isEmpty(title));
        sendNotification(id, title, text, data, showNotification);
    }
}
 
开发者ID:jsayol,项目名称:cordova-plugin-firebase-sdk,代码行数:41,代码来源:MessagingService.java

示例5: notify

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Fire a system tray notification from the FCM message mimicking the default notification format and behavior applied when the app is in background
 *
 * @param remoteMessage FCM remote message
 * @throws IllegalArgumentException if the remote message does not contain notification information
 */
public void notify(RemoteMessage remoteMessage) throws IllegalArgumentException {
    RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();
    if (fcmNotification == null)
        throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);

    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

    String tag = fcmNotification.getTag();
    notificationManager.notify(tag, tag == null ? remoteMessage.getMessageId().hashCode() : 0, new RemoteMessageToNotificationMapper(context).map(remoteMessage));
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:17,代码来源:RemoteMessageNotifier.java

示例6: mapToNotificationBuilder

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
/**
 * Map a FCM remote message into a System Notification Builder mimicking the default notification format and behavior applied when the app is in background
 *
 * @param remoteMessage FCM remote message
 * @return The notification builder configured with the notification information of the remote message
 * @throws IllegalArgumentException if the remote message does not contain notification information
 */
public NotificationCompat.Builder mapToNotificationBuilder(RemoteMessage remoteMessage) throws IllegalArgumentException {
    RemoteMessage.Notification fcmNotification = remoteMessage.getNotification();

    if (fcmNotification == null)
        throw new IllegalArgumentException(ErrorMessages.NO_NOTIFICATION_MSG);

    String body = parseBody(fcmNotification);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
    builder.setContentTitle(parseTitle(fcmNotification))
            .setContentText(body)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(body))
            .setSmallIcon(parseIcon(fcmNotification))
            .setAutoCancel(true);

    Integer color;
    if ((color = parseColor(fcmNotification)) != null) {
        builder.setColor(color);
    }

    int soundFileResId;
    if (fcmNotification.getSound() != null &&
            !fcmNotification.getSound().equals("default") &&
            (soundFileResId = context.getResources().getIdentifier(fcmNotification.getSound(), "raw", context.getPackageName())) != 0) {

        builder.setSound(Uri.parse("android.resource://" + context.getPackageName() + "/" + soundFileResId));

    } else if (fcmNotification.getSound() != null) {
        builder.setDefaults(Notification.DEFAULT_SOUND);
    }

    builder.setContentIntent(createNotificationPendingItent(remoteMessage));

    return builder;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:42,代码来源:RemoteMessageToNotificationMapper.java

示例7: parseTitle

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
private String parseTitle(RemoteMessage.Notification fcmNotification) {
    String title = fcmNotification.getTitle();
    if (title == null) {
        String titleLocalizationKey = fcmNotification.getTitleLocalizationKey();
        if (titleLocalizationKey != null) {
            title = getLocalizedString(titleLocalizationKey, fcmNotification.getTitleLocalizationArgs());
        }
        if (title == null) {
            title = getApplicationName();
        }
    }
    return title;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:14,代码来源:RemoteMessageToNotificationMapper.java

示例8: parseBody

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
@Nullable
private String parseBody(RemoteMessage.Notification fcmNotification) {
    String body = fcmNotification.getBody();
    if (body == null) {
        String bodyLocalizationKey = fcmNotification.getBodyLocalizationKey();
        if (bodyLocalizationKey != null) {
            body = getLocalizedString(bodyLocalizationKey, fcmNotification.getBodyLocalizationArgs());
        }
    }
    return body;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:12,代码来源:RemoteMessageToNotificationMapper.java

示例9: parseIcon

import com.google.firebase.messaging.RemoteMessage; //导入方法依赖的package包/类
private int parseIcon(RemoteMessage.Notification fcmNotification) {
    String notificationIcon = fcmNotification.getIcon();

    int iconResId = 0;
    if (notificationIcon != null) {
        iconResId = context.getResources().getIdentifier(notificationIcon, "drawable", context.getPackageName());
    }

    if (iconResId == 0) {
        iconResId = getResourceIdFromApplicationMetadata("com.google.firebase.messaging.default_notification_icon");
        if (iconResId == 0)
            iconResId = getApplicationIconResId();
    }
    return iconResId;
}
 
开发者ID:franmontiel,项目名称:FcmNotificationHandler,代码行数:16,代码来源:RemoteMessageToNotificationMapper.java


注:本文中的com.google.firebase.messaging.RemoteMessage.Notification方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。