Skip to content

Instantly share code, notes, and snippets.

@astjohn
Created October 3, 2017 20:19
Show Gist options
  • Save astjohn/7196c0a36fae4bc800d2a577967920be to your computer and use it in GitHub Desktop.
Save astjohn/7196c0a36fae4bc800d2a577967920be to your computer and use it in GitHub Desktop.
// Service class to obtain push notification token
//
//
import com.sitata.sdk.controller.SitataController;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
SitataController.setFcmToken(refreshedToken);
}
}
// Service class to receive incoming push notifications
//
//
import com.sitata.sdk.controller.SitataController;
import com.sitata.sdk.gui.SitataGui;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Got push from: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// to only sync data, without displaying anything:
// SitataController.handlePushData( remoteMessage );
// sync data AND display push notification:
SitataGui.showPushNotification( remoteMessage,
// icon for the notification
R.drawable.ic_my_push_notif_icon,
// fallback activity to launch when a notification is clicked and there isn't
// a specific SDK UI activity to launch. e.g. new trip notification
MyMainActivity.class );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment