Android Firebase Cloud Messaging

What is Firebase?
Firebase is a collection of tools that developers can use in their apps. for example analytics, crash reporter, and authentication  and so on. Authentication help developers authenticate users with different ways without a backen implementation.
some of firebase features are restricted in iran like authentication. but some of features like analytic, crash report and and cloud messaging can use in iran. some of firebase features are free like cloud messaging and some of them are free just for a limit.
android studio has firebase assistant to add firebase features to android projects.
Firebase cloud messaging
FCM is new version of GCM(Google could messaging). Google say everyone who use GCM to upgrade to FCM. Implementation of GCM is different with FCM. in GCM developer calls a method to get registration token but in FCM when app installs and doesn’t have registration token firebase SDK gets the registration token automatically and then calls the onRefreshToken. Developer can’t write a code in app that cause the onRefreshToken calls.
before we can use FCM in our project,(Android, iOS or web) we should add the project to firebase console. after that creating a project in console, in project page we can add android, iOS or web app. for each of apps we should enter specific information, for example for an android app we should enter package name and for iOS app we should enter the bundle ID.
FCM message types:
there is two types of messages, notification messages and data messages. if the message that is sent to app is notification message and app is in background, firebase SDK automatically fire a notification. if app is in foreground onMessageRecevied will call in android.
if message is sent to app is data message, firebase SDK doesn’t show a notification automatically and onMessageRecevied will call in background and foreground state. 
two type of messages in FCM determine with JSON structure. notification message is like the following example:

data message is like the following:


Firebase have a console that you can use it to send notification type messages. in real world examples we need to run some query on our database and then send notification to some of users. so we need to have app server. 

in app server we use CURL for sending messages to google servers and google servers send the message to our clients.
app server need to have notification token to prepare notification JSON and app server use server key in CURL.
in app server side, we need mysql for save users data and messages. and we need REST API that we use for sending messages.
if user A wants to send a message to user B in a chat application, in app message will send to Rest api and PHP codes that exist for Rest API will save the message in mysql tables and use CURL for send the messages to google servers.
if android app wants to send message to app server and doesn’t want to use REST API, there is a SDK classes that use Sender ID. FCM then use Sender ID and find the app server and send message to it. when app server wants to send message to FCM it uses server key in CURL.

درباره نویسنده

پست های مرتبط

3 نظر

  1. reyhane

    سلام با توجه به قدیمی بودن تاریخ پست میخواستم بپرسم هنوز crash report برای ایران آزاد هست؟ اگه در اپلیکیشنی استفاده کنیم و بعد این سرویس فیلتر بشه برای اپلیکیشن مشکلی بوجود میاد؟
    سرویس جایگزینی براش میشناسین ممنون میشم معرفی کنین

    پاسخ
    1. فهیمه قاسمی
      فهیمه قاسمی

      سلام. بله این سرویس برای ایران هنوز قابل استفاده هست. گرش ریپورت گوگل خیلی خوب و قوی نبود. یه سرویسی بود به اسم crashlytics که خیلی خوب کار کرده بود. گوگل خریدش و با Firebase الان قابل استفاده هست. برای کرش ریپورست غیر از فایربیس میتونین از سنتری هم استفاده کنین. ممکنه پنلش برای ایران تحریم باشه و شما لازم باشه که از ابزار گذر از تحریم استفاده کنین. ولی کرش ها از سمت اپ‌های ایرانی به سمت سرورش میان. crashlytics هم همینطوری بود یعنی پنلش برای ایران تحریم بود ولی کرش ها از سمت اپi‌های ایرانی سمت پنل میومدن.

      پاسخ

پاسخ

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

7 − 2 =