User Guide: SDKs > Flutter SDK > Invoking Messaging Service
Invoking Messaging Service
A developer should register with Google Cloud Messaging (GCM) to get the device token that is used to register with Volt Foundry Messaging. Also, a developer should fetch the deviceId and user-friendlyId to create an instance of the messaging service.
The following are the methods you can use for a messaging service.
- Register
- Unregister
- Update Geo Location
- Fetch All Messages
- Mark Message as Read
- Get Message Content
Register
// Sample code to register for the messaging service
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fcmId = "<Your fcmId here>";
var deviceId = "<Your deviceId here>";
var ufId = "<Your ufId here>";
voltmxSdkFlutter.register(fcmId, deviceId, ufId, onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});
Note : Call these methods only after successful completion of voltmxSdkFlutter.initializeSDK. For more details, refer to the
Init method.
Unregister
// Sample code to unregister from the messaging service
var voltmxSdkFlutter = VoltmxSdkFlutter();
voltmxSdkFlutter.unregister(
onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});
Update geo location
// Sample code to update geo location
var voltmxSdkFlutter = VoltmxSdkFlutter();
var latitude = "<Your latitude here>";
var longitude = "<Your longitude here>";
var locationName = "<Your locationName here>";
voltmxSdkFlutter.updateGeoLocation(latitude, longitude, locationName, onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});
Fetch all messages
// Sample code to fetch all the messages
var voltmxSdkFlutter = VoltmxSdkFlutter();
int startIndex = 0;
int pageSize = 10;
voltmxSdkFlutter.fetchAllMessages(startIndex, pageSize,
onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});
Note: Fetch all messages api returns only part of a message. To get full content of the message, use the Get message Content method below.
Mark message as read
// Sample code to mark message as Read
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fetchId = "<Your fetchId here>";
voltmxSdkFlutter.markMessageRead(fetchId, onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});
Get message content
// Sample code to get message content
var voltmxSdkFlutter = VoltmxSdkFlutter();
var fetchId = "<Your fetchId here>";
voltmxSdkFlutter.fetchMessageContent(fetchId, onSuccess: (response) {
// Handle the success case here
}, onFailure: (response) {
// Handle the failure case here
});