@Override public void subscribeToPushChannel(String channel) { FirebaseMessaging.getInstance().subscribeToTopic(channel); }
@Override public void unsubscribeToPushChannel(String channel) { FirebaseMessaging.getInstance().unsubscribeFromTopic(channel); }
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); Log.d("Msg", "Message received ["+remoteMessage+"]"); // Create Notification Intent intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 1410, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_stat_name) .setContentTitle("Message") .setContentText(remoteMessage.getNotification().getBody()) .setAutoCancel(true) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(1410, notificationBuilder.build()); } }
@Override public void onMessageReceived(RemoteMessage remoteMessage) { super.onMessageReceived(remoteMessage); PLog.d(ParseFCM.TAG, "onMessageReceived"); String pushId = remoteMessage.getData().get("push_id"); String timestamp = remoteMessage.getData().get("time"); String dataString = remoteMessage.getData().get("data"); String channel = remoteMessage.getData().get("channel"); JSONObject data = null; if (dataString != null) { try { data = new JSONObject(dataString); } catch (JSONException e) { PLog.e(ParseFCM.TAG, "Ignoring push because of JSON exception while processing: " + dataString, e); return; } } PushRouter.getInstance().handlePush(pushId, timestamp, channel, data); } }
private void sendNotification(DeviceInfo device, String notificationBase64) { Message msg = Message.builder() .putData("notification", notificationBase64) .setToken(device.fcm_device_info.token) .build(); try { String resp = FirebaseMessaging.getInstance().send(msg); log.info("Firebase message sent: %s", resp); } catch(FirebaseMessagingException e) { log.error("Error sending firebase notification: %s", e.getErrorCode(), e); } } }
/** * Creates a new notification with the given title, body and icon. Overrides the options set via * {@link Notification}. * * @param title Title of the notification. * @param body Body of the notification. * @param icon URL to the notifications icon. */ public WebpushNotification(String title, String body, @Nullable String icon) { this(builder().setTitle(title).setBody(body).setIcon(icon)); }
@Override public void onDeletedMessages() { super.onDeletedMessages(); } }
/** * Builds a new {@link CriticalSound} instance from the fields set on this builder. * * @return A non-null {@link CriticalSound}. * @throws IllegalArgumentException If the volume value is out of range. */ public CriticalSound build() { return new CriticalSound(this); } }
/** * Creates a new {@link ApnsConfig.Builder}. * * @return A {@link ApnsConfig.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link Message} instance from the parameters set on this builder. * * @return A new {@link Message} instance. * @throws IllegalArgumentException If any of the parameters set on the builder are invalid. */ public Message build() { return new Message(this); } }
/** * Builds a new {@link Aps} instance from the fields set on this builder. * * @return A non-null {@link Aps}. * @throws IllegalArgumentException If the alert is specified both as an object and a string. * Or if the same field is set both using a setter method, and as a custom field. */ public Aps build() { return new Aps(this); } }
/** * Creates a new {@link ApsAlert.Builder}. * * @return A {@link ApsAlert.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link WebpushNotification.Builder}. * * @return A {@link WebpushNotification.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link Message.Builder}. * * @return A {@link Message.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link WebpushConfig} instance from the parameters set on this builder. * * @return A new {@link WebpushConfig} instance. * @throws IllegalArgumentException If any of the parameters set on the builder are invalid. */ public WebpushConfig build() { return new WebpushConfig(this); } }
/** * Creates a new {@link CriticalSound.Builder}. * * @return A {@link CriticalSound.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link AndroidConfig.Builder}. * * @return A {@link AndroidConfig.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link AndroidNotification.Builder}. * * @return A {@link AndroidNotification.Builder} instance. */ public static Builder builder() { return new Builder(); }
/** * Creates a new {@link ApnsConfig} instance from the parameters set on this builder. * * @return A new {@link ApnsConfig} instance. * @throws IllegalArgumentException If any of the parameters set on the builder are invalid. */ public ApnsConfig build() { return new ApnsConfig(this); } }
/** * Creates a new {@link AndroidConfig} instance from the parameters set on this builder. * * @return A new {@link AndroidConfig} instance. * @throws IllegalArgumentException If any of the parameters set on the builder are invalid. */ public AndroidConfig build() { return new AndroidConfig(this); } }